How to resolve the algorithm Ordered words step by step in the Seed7 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Ordered words step by step in the Seed7 programming language

Table of Contents

Problem Statement

An   ordered word   is a word in which the letters appear in alphabetic order. Examples include   abbey   and   dirt. Find and display all the ordered words in the dictionary   unixdict.txt   that have the longest word length. (Examples that access the dictionary file locally assume that you have downloaded this file yourself.)
The display needs to be shown on this page.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Ordered words step by step in the Seed7 programming language

Source code in the seed7 programming language

$ include "seed7_05.s7i";

const func boolean: isOrdered (in string: word) is func
  result
    var boolean: ordered is TRUE;
  local
    var integer: index is 0;
  begin
    for index range 1 to pred(length(word)) do
      if word[index] > word[succ(index)] then
        ordered := FALSE;
      end if;
    end for;
  end func;

const proc: write (in array string: wordList) is func
  local
    var string: word is "";
  begin
    for word range wordList do
      writeln(word);
    end for;
  end func;

const proc: main is func
  local
    var file: dictionary is STD_NULL;
    var string: word is "";
    var integer: length is 0;
    var array string: wordList is 0 times "";
  begin
    dictionary := open("unixdict.txt", "r");
    if dictionary <> STD_NULL then
      readln(dictionary, word);
      while not eof(dictionary) do
        if isOrdered(lower(word)) then
          if length(word) > length then
            length := length(word);
            wordList := [] (word);
          elsif length(word) = length then
            wordList &:= word;
          end if;
        end if;
        readln(dictionary, word);
      end while;
      close(dictionary);
    end if;
    write(wordList);
  end func;

  

You may also check:How to resolve the algorithm Associative array/Creation step by step in the Futhark programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bogosort step by step in the Rust programming language
You may also check:How to resolve the algorithm String length step by step in the jq programming language
You may also check:How to resolve the algorithm Langton's ant step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm System time step by step in the Smalltalk programming language