57 lines
1.4 KiB
Text
57 lines
1.4 KiB
Text
/* NetRexx */
|
|
options replace format comments java crossref symbols nobinary
|
|
|
|
runSample(arg)
|
|
return
|
|
|
|
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
method findMostAnagrams(arg) public static 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 = 0
|
|
maxWords = 0
|
|
loop label w_ forever
|
|
aWord = dictionaryReader.readLine()
|
|
if aWord = null then leave w_
|
|
chars = aWord.toCharArray()
|
|
Arrays.sort(chars)
|
|
key = Rexx(chars)
|
|
parse anagrams[key] count aWords
|
|
aWords = (aWords aWord).space()
|
|
maxWords = maxWords.max(aWords.words())
|
|
anagrams[key] = aWords.words() aWords
|
|
end w_
|
|
dictionaryReader.close
|
|
|
|
loop key over anagrams
|
|
parse anagrams[key] count aWords
|
|
if count >= maxWords then
|
|
say aWords
|
|
else
|
|
anagrams[key] = null -- remove unwanted elements from the indexed string
|
|
end key
|
|
|
|
return
|
|
|
|
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
method runSample(arg) public static
|
|
|
|
Do
|
|
findMostAnagrams(arg)
|
|
Catch ex = Exception
|
|
ex.printStackTrace()
|
|
End
|
|
|
|
Return
|