Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
40
Task/Anagrams/Phix/anagrams.phix
Normal file
40
Task/Anagrams/Phix/anagrams.phix
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
integer fn = open("unixdict.txt","r")
|
||||
sequence words = {}, anagrams = {}, last="", letters
|
||||
object word
|
||||
integer maxlen = 1
|
||||
|
||||
while 1 do
|
||||
word = trim(gets(fn))
|
||||
if atom(word) then exit end if
|
||||
if length(word) then
|
||||
letters = sort(word)
|
||||
words = append(words, {letters, word})
|
||||
end if
|
||||
end while
|
||||
close(fn)
|
||||
|
||||
words = sort(words)
|
||||
for i=1 to length(words) do
|
||||
{letters,word} = words[i]
|
||||
if letters=last then
|
||||
anagrams[$] = append(anagrams[$],word)
|
||||
if length(anagrams[$])>maxlen then
|
||||
maxlen = length(anagrams[$])
|
||||
end if
|
||||
else
|
||||
last = letters
|
||||
anagrams = append(anagrams,{word})
|
||||
end if
|
||||
end for
|
||||
|
||||
puts(1,"\nMost anagrams:\n")
|
||||
for i=1 to length(anagrams) do
|
||||
last = anagrams[i]
|
||||
if length(last)=maxlen then
|
||||
for j=1 to maxlen do
|
||||
if j>1 then puts(1,", ") end if
|
||||
puts(1,last[j])
|
||||
end for
|
||||
puts(1,"\n")
|
||||
end if
|
||||
end for
|
||||
Loading…
Add table
Add a link
Reference in a new issue