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

Published on 12 May 2024 09:40 PM
#E

How to resolve the algorithm Ordered words step by step in the E 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 E programming language

Source code in the e programming language

pragma.enable("accumulator")

def words := .getText().split("\n")
def ordered := accum [] for word ? (word.sort() <=> word) in words { _.with(word) }
def maxLen := accum 0 for word in ordered { _.max(word.size()) }
def maxOrderedWords := accum [] for word ? (word.size() <=> maxLen) in ordered { _.with(word) }
println(" ".rjoin(maxOrderedWords))

def best := [].diverge()
for `@word$\n` ? (word.sort() <=> word) in  {
  if (best.size() == 0) {
    best.push(word)
  } else if (word.size() > best[0].size()) {
    best(0) := [word] # replace all
  } else if (word.size() <=> best[0].size()) {
    best.push(word)
  }
}
println(" ".rjoin(best.snapshot()))

  

You may also check:How to resolve the algorithm Brace expansion step by step in the C# programming language
You may also check:How to resolve the algorithm Sum multiples of 3 and 5 step by step in the Crystal programming language
You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Sierpinski triangle step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Nested templated data step by step in the Racket programming language