Anagrams: Difference between revisions

Content added Content deleted
Line 1,975: Line 1,975:


=={{header|Elena}}==
=={{header|Elena}}==
ELENA 3.4:
ELENA 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 extensions'text.
import system'routines;
import system'io;
import system'collections;
import extensions;
import extensions'routines;
import extensions'text;


extension op
extension op
{
{
T<literal> normalized
string normalized()
= self toArray; ascendant; summarize(StringWriter new).
= self.toArray().ascendant().summarize(new StringWriter());
}
}


public program
public program()
{
[
auto aDictionary := Map<literal,object>().
auto dictionary := new Map<string,object>();

File new("unixdict.txt"); forEachLine(:aWord)
File.assign("unixdict.txt").forEachLine:(word)
[
{
var s := aWord.
var aKey := aWord normalized.
var key := word.normalized();
var anItem := aDictionary[aKey].
var item := dictionary[key];
if (nil == anItem)
if (nil == item)
[
{
anItem := ArrayList new.
item := new ArrayList();
aDictionary[aKey] := anItem.
dictionary[key] := item
].
};
anItem append:aWord.
item.append:word
].
};


dictionary.Values
aDictionary values;
sort(:aFormer:aLater)( aFormer item2; length > aLater item2; length );
.sort:(former,later => former.Item2.Length > later.Item2.Length )
top:20; forEach(:aPair)[ console printLine(aPair item2) ].
.top:20
.forEach:(pair){ console.printLine(pair.Item2) };
console readChar
console.readChar()
]</lang>
}</lang>
{{out}}
{{out}}
<pre>
<pre>