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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Anagrams step by step in the MUMPS 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 MUMPS programming language

Source code in the mumps programming language

Anagrams	New ii,file,longest,most,sorted,word
	Set file="unixdict.txt"
	Open file:"r" Use file
	For  Quit:$ZEOF  DO
	. New char,sort
	. Read word Quit:word=""
	. For ii=1:1:$Length(word) Do
	. . Set char=$ASCII(word,ii)
	. . If char>64,char<91 Set char=char+32
	. . Set sort(char)=$Get(sort(char))+1
	. . Quit
	. Set (sorted,char)="" For  Set char=$Order(sort(char)) Quit:char=""  Do
	. . For ii=1:1:sort(char) Set sorted=sorted_$Char(char)
	. . Quit
	. Set table(sorted,word)=1
	. Quit
	Close file
	Set sorted="" For  Set sorted=$Order(table(sorted)) Quit:sorted=""  Do
	. Set ii=0,word="" For  Set word=$Order(table(sorted,word)) Quit:word=""  Set ii=ii+1
	. Quit:ii<2
	. Set most(ii,sorted)=1
	. Quit
	Write !,"The anagrams with the most variations:"
	Set ii=$Order(most(""),-1)
	Set sorted="" For  Set sorted=$Order(most(ii,sorted)) Quit:sorted=""  Do
	. Write ! Set word="" For  Set word=$Order(table(sorted,word)) Quit:word=""  Write "  ",word
	. Quit
	Write !,"The longest anagrams:"
	Set ii=$Order(longest(""),-1)
	Set sorted="" For  Set sorted=$Order(longest(ii,sorted)) Quit:sorted=""  Do
	. Write ! Set word="" For  Set word=$Order(table(sorted,word)) Quit:word=""  Write "  ",word
	. Quit
	Quit

Do Anagrams

  

You may also check:How to resolve the algorithm Langton's ant step by step in the bc programming language
You may also check:How to resolve the algorithm Iterated digits squaring step by step in the Swift programming language
You may also check:How to resolve the algorithm Koch curve step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Non-decimal radices/Input step by step in the MATLAB / Octave programming language
You may also check:How to resolve the algorithm Loops/Break step by step in the M2000 Interpreter programming language