Textonyms: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: Removed an apparent editing artefact which impeded compilation) |
(added MiniScript example) |
||
Line 2,070: | Line 2,070: | ||
{2,8,7,3,8,8,3,7} {BURETTES,CURETTES} |
{2,8,7,3,8,8,3,7} {BURETTES,CURETTES} |
||
{3,7,8,2,8,3,7} {EQUATES,ESTATES}</pre> |
{3,7,8,2,8,3,7} {EQUATES,ESTATES}</pre> |
||
=={{header|Miniscript}}== |
|||
<lang MiniScript>import "listUtil" |
|||
import "mapUtil" |
|||
groups = "abc def ghi jkl mno pqrs tuv wxyz".split |
|||
charToNum = {} |
|||
for i in groups.indexes |
|||
for ch in groups[i] |
|||
charToNum[ch] = i + 2 |
|||
end for |
|||
end for |
|||
words = file.readLines("/sys/data/englishWords.txt") |
|||
wordToNum = function(word) |
|||
parts = word.split("") |
|||
parts.apply function(ch) |
|||
return charToNum[ch] |
|||
end function |
|||
return parts.join("") |
|||
end function |
|||
numToWords = {} |
|||
moreThan1Word = 0 |
|||
for word in words |
|||
num = wordToNum(word.lower) |
|||
if numToWords.hasIndex(num) then |
|||
numToWords[num].push word |
|||
else |
|||
numToWords[num] = [word] |
|||
end if |
|||
if numToWords[num].len == 2 then moreThan1Word = moreThan1Word + 1 |
|||
end for |
|||
print "There are " + words.len + " words in englishWords.txt which can be represented by the digit key mapping." |
|||
print "They require " + numToWords.len + " digit combinations to represent them." |
|||
print moreThan1Word + " digit combinations represent Textonyms." |
|||
while true |
|||
print |
|||
inp = input("Enter a word or digit combination: ") |
|||
if not inp then break |
|||
if val(inp) > 0 then |
|||
print inp + " -> " + numToWords.get(inp) |
|||
else |
|||
num = wordToNum(inp.lower) |
|||
print "Digit key combination for """ + inp + """ is: " + num |
|||
print num + " -> " + numToWords.get(num) |
|||
end if |
|||
end while</lang> |
|||
{{out}} |
|||
<pre>There are 64664 words in englishWords.txt which can be represented |
|||
by the digit key mapping. |
|||
They require 59148 digit combinations to represent them. |
|||
4028 digit combinations represent Textonyms. |
|||
Enter a word or digit combination: 2877464 |
|||
2877464 -> ["burping", "bussing", "cupping", "cursing", "cussing"] |
|||
Enter a word or digit combination: phoning |
|||
Digit key combination for "phoning" is: 7466464 |
|||
7466464 -> ["phoning", "pinning", "rimming", "shooing", "sinning"]</pre> |
|||
=={{header|Nim}}== |
=={{header|Nim}}== |