60 lines
1.6 KiB
Text
60 lines
1.6 KiB
Text
/* NetRexx */
|
|
options replace format comments java crossref symbols nobinary
|
|
|
|
class RAnagramsV01 public
|
|
|
|
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
method runSample(arg) public signals MalformedURLException, IOException
|
|
parse arg localFile .
|
|
isr = Reader
|
|
if localFile = '' then do
|
|
durl = URL("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt")
|
|
dictFrom = durl.toString()
|
|
isr = InputStreamReader(durl.openStream())
|
|
end
|
|
else do
|
|
dictFrom = localFile
|
|
isr = FileReader(localFile)
|
|
end
|
|
say 'Searching' dictFrom 'for anagrams'
|
|
dictionaryReader = BufferedReader(isr)
|
|
|
|
anagrams = Map HashMap()
|
|
aWord = String
|
|
count = 0
|
|
loop label w_ forever
|
|
aWord = dictionaryReader.readLine()
|
|
if aWord = null then leave w_
|
|
chars = aWord.toCharArray()
|
|
Arrays.sort(chars)
|
|
key = String(chars)
|
|
if (\anagrams.containsKey(key)) then do
|
|
anagrams.put(key, ArrayList())
|
|
end
|
|
(ArrayList anagrams.get(key)).add(Object aWord)
|
|
count = Math.max(count, (ArrayList anagrams.get(key)).size())
|
|
end w_
|
|
dictionaryReader.close
|
|
|
|
ani = anagrams.values().iterator()
|
|
loop label a_ while ani.hasNext()
|
|
ana = ani.next()
|
|
if (ArrayList ana).size() >= count then do
|
|
say ana
|
|
end
|
|
end a_
|
|
|
|
return
|
|
|
|
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
method main(args = String[]) public static
|
|
|
|
arg = Rexx(args)
|
|
Do
|
|
ra = RAnagramsV01()
|
|
ra.runSample(arg)
|
|
Catch ex = Exception
|
|
ex.printStackTrace()
|
|
End
|
|
|
|
return
|