Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
60
Task/Anagrams/NetRexx/anagrams-1.netrexx
Normal file
60
Task/Anagrams/NetRexx/anagrams-1.netrexx
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/* 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
|
||||
57
Task/Anagrams/NetRexx/anagrams-2.netrexx
Normal file
57
Task/Anagrams/NetRexx/anagrams-2.netrexx
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/* 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue