(phixonline)--> with javascript_semantics 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) string keycode = repeat(' ',length(word)) for i=1 to length(word) do integer ch = word[i] assert(ch>='a' and ch<='z') keycode[i] = digit[ch] end for return {keycode,word} end function function az(string word) return min(word)>='a' and max(word)<='z' end function sequence words = apply(filter(unix_dict(),az),digits), max_idx, long_idx string word, keycode, last = "" integer keycode_count = 0, textonyms = 0, this_count = 0, max_count = 0, longest = 0 printf(1,"There are %d words in unixdict.txt which can be represented by the digit key mapping.\n",{length(words)}) -- Sort by keycode: while words are ordered we get -- eg {"a","ab","b","ba"} -> {"2","22","2","22"} words = sort(deep_copy(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 if this_count>max_count then max_idx = {i} else max_idx &= i end if max_count = this_count end if else keycode_count += 1 last = keycode this_count = 1 end if if length(word)>=longest then if length(word)>longest then long_idx = {i} else long_idx &= i end if longest = length(word) 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}) printf(1,"The maximum number of textonyms for a particular digit key mapping is %d:\n",{max_count}) for i=1 to length(max_idx) do integer k = max_idx[i], l = k-max_count+1 string dups = join(vslice(words[l..k],2),"/") printf(1," %s encodes %s\n",{words[k][1],dups}) end for printf(1,"The longest words are %d characters long\n",longest) printf(1,"Encodings with this length are:\n") for i=1 to length(long_idx) do printf(1," %s encodes %s\n",words[long_idx[i]]) end for