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

Published on 12 May 2024 09:40 PM

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

Source code in the erlang programming language

-module( ordered_words ).

-export( [is_ordered/1, task/0] ).

is_ordered( Word ) -> lists:sort( Word ) =:=  Word.

task() ->
    ok = find_unimplemented_tasks:init_http(),
    Ordered_words = [X || X <- words(), is_ordered(X)],
    Sorted_longest_length_first = lists:reverse( sort_with_length( Ordered_words ) ),
    [{Max_length, _Word1} | _T] = Sorted_longest_length_first,
    Longest_length_first = lists:takewhile( fun({Length, _Word2}) -> Length =:= Max_length end, Sorted_longest_length_first ),
    [X || {_Length, X} <- Longest_length_first].



sort_with_length( Words ) ->
    Words_with_length_first = [{erlang:length(X), X} || X <- Words],
    lists:sort( Words_with_length_first ).

words() -> anagrams_deranged:words_from_url( "http://www.puzzlers.org/pub/wordlists/unixdict.txt" ).


  

You may also check:How to resolve the algorithm Tau function step by step in the F# programming language
You may also check:How to resolve the algorithm Draw a pixel step by step in the Delphi programming language
You may also check:How to resolve the algorithm Input loop step by step in the Python programming language
You may also check:How to resolve the algorithm Knapsack problem/Continuous step by step in the Ada programming language
You may also check:How to resolve the algorithm Filter step by step in the Lua programming language