Anagrams: Difference between revisions

Content deleted Content added
Alextretyak (talk | contribs)
Line 1,975:
 
=={{header|Elena}}==
ELENA 3.4.0:
<lang elena>// Two or more words can be composed of the same characters, but in
<lang elena>import system'routines.
// a different order. Using the word list at
import system'io.
// http://www.puzzlers.org/pub/wordlists/unixdict.txt, find the sets of words
import system'collections.
// that share the same characters that contain the most words in them.
import extensions.
 
import extensions'routines.
import extensionssystem'text.routines;
import system'io.;
import system'collections.;
import extensions.;
<lang elena>import systemextensions'routines.;
import extensions'routines.text;
 
extension op
{
T<literal>string normalized()
= self .toArray; ().ascendant; ().summarize(StringWriter new StringWriter().);
}
 
public program()
{
[
auto aDictionarydictionary := new Map<literalstring,object>().;
 
File new.assign("unixdict.txt"); .forEachLine(:aWord(word)
[ {
var s := aWord.
var aKeykey := aWord word.normalized.();
var anItemitem := aDictionarydictionary[aKeykey].;
if (nil == anItemitem)
[{
anItemitem := ArrayList new. ArrayList();
aDictionarydictionary[aKeykey] := anItem.item
].};
anItem item.append:aWord.word
].};
 
dictionary.Values
aDictionary values;
.sort(:aFormer:aLater)(former,later aFormer=> item2; lengthformer.Item2.Length > aLater item2; lengthlater.Item2.Length );
.top:20; forEach(:aPair)[ console printLine(aPair item2) ].
.forEach:(pair){ console.printLine(pair.Item2) };
console .readChar()
]}</lang>
{{out}}
<pre>