RosettaCodeData/Task/Textonyms/Phix/textonyms.phix

64 lines
1.8 KiB
Plaintext

sequence digit = repeat(-1,255)
digit['a'..'c'] = '2'
digit['d'..'f'] = '3'
digit['g'..'i'] = '4'
digit['j'..'l'] = '5'
digit['m'..'o'] = '6'
digit['p'..'s'] = '7'
digit['t'..'v'] = '8'
digit['w'..'z'] = '9'
function digits(string word)
for i=1 to length(word) do
integer ch = word[i]
if ch<'a' or ch>'z' then return "" end if
word[i] = digit[ch]
end for
return word
end function
sequence words = {}, last=""
object word, keycode
integer keycode_count = 0, textonyms = 0,
this_count = 0, max_count = 0, max_idx
integer fn = open("demo\\unixdict.txt","r")
while 1 do
word = trim(gets(fn))
if atom(word) then exit end if
keycode = digits(word)
if length(keycode) then
words = append(words, {keycode, word})
end if
end while
close(fn)
printf(1,"There are %d words in unixdict.txt which can be represented by the digit key mapping.\n",{length(words)})
words = sort(words)
for i=1 to length(words) do
{keycode,word} = words[i]
if keycode=last then
textonyms += this_count=1
this_count += 1
if this_count>max_count then
max_count = this_count
max_idx = i
end if
else
keycode_count += 1
last = keycode
this_count = 1
end if
end for
printf(1,"They require %d digit combinations to represent them.\n",{keycode_count})
printf(1,"%d digit combinations represent Textonyms.\n",{textonyms})
sequence dups = {}
for i=max_idx-max_count+1 to max_idx do
dups = append(dups,words[i][2])
end for
printf(1,"The maximum number of textonyms for a particular digit key mapping is %d:\n",{max_count})
printf(1," %s encodes %s\n",{words[max_idx][1],join(dups,"/")})