How to resolve the algorithm Anagrams step by step in the Phixmonti programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Anagrams step by step in the Phixmonti programming language

Table of Contents

Problem Statement

When two or more words are composed of the same characters, but in a different order, they are called anagrams. Using the word list at   http://wiki.puzzlers.org/pub/wordlists/unixdict.txt, find the sets of words that share the same characters that contain the most words in them.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Anagrams step by step in the Phixmonti programming language

Source code in the phixmonti programming language

include ..\Utilitys.pmt

"unixdict.txt" "r" fopen var f

( )

true while
    f fgets
    dup -1 == if
        drop
        f fclose
        false
    else
        -1 del 
        dup sort swap 2 tolist 0 put 
        true
    endif   
endwhile

sort

"" var prev
( ) var prov
( ) var res
0 var maxlen

len for
    get 1 get dup prev != if
        res prov len maxlen > if len var maxlen endif
        0 put var res ( ) var prov
    endif
    var prev
    2 get nip
    prov swap 0 put var prov
endfor

res

len for
    get len maxlen == if ? else drop endif
endfor

include ..\Utilitys.pmt

( )
newd var dict
0 var maxlen

"unixdict.txt" "r" fopen var f
true while
    f fgets
    dup -1 == if
        drop
        f fclose
        false
    else
        -1 del 
        0 put
        true
    endif   
endwhile

len for
    get dup >ps sort dup >ps
    dict swap getd dup
    "Unfound" == if
        drop ps> ps> 1 tolist 
    else
        ps> swap ps> 0 put len maxlen max var maxlen
    endif
    2 tolist setd var dict
endfor

drop dict 2 get nip

len for
    get len maxlen == if ? else drop endif
endfor

  

You may also check:How to resolve the algorithm Population count step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Numbers with equal rises and falls step by step in the C++ programming language
You may also check:How to resolve the algorithm CUSIP step by step in the C++ programming language
You may also check:How to resolve the algorithm Benford's law step by step in the Perl programming language
You may also check:How to resolve the algorithm Calculating the value of e step by step in the FOCAL programming language