Textonyms: Difference between revisions
Content deleted Content added
m →{{header|Haskell}}: (Tidied) |
|||
Line 1,209:
------------------------ TEXTONYMS -----------------------
digitEncoded ::
M.Map Char Char ->
[String] ->
[(String, String)]
digitEncoded dict =
mapMaybe $
Line 1,238 ⟶ 1,241:
s <- readFile fp
let encodings = digitEncoded charDict $ lines s
codeGroups =
groupBy
(on (==) snd)
. sortOn snd
$ encodings
textonyms = filter ((1 <) . length) codeGroups
mapM_
Line 1,246 ⟶ 1,253:
<> " words in "
<> fp
<> " which can be represented
<> "
"\nThey require "
<> show (length codeGroups)
<> " digit combinations to represent them.",
show (length textonyms)
<> " digit combinations represent textonyms.",
""
]
let codeLength = length . snd . head
[ambiguous, longer] =
definedSamples
[wa, wl] = maximum . fmap codeLength <$> [ambiguous, longer]▼
5
textonyms
[length, codeLength]
[wa, wl] =
<$> [ambiguous, longer]
mapM_ putStrLn $
"Five most ambiguous:" :
fmap (showTextonym wa) ambiguous
<> (
"Five longest:" :
fmap
(showTextonym wl)
longer
)
------------------------- DISPLAY ------------------------
showTextonym :: Int -> [(String, String)] -> String
showTextonym w ts =
concat
" -> ",
unwords $ fmap fst ts
]
where
rjust n c = (drop . length) <*> (replicate n c <>)</lang>
{{Out}}
<pre>There are 24978 words in unixdict.txt which can be represented
by the digit key mapping.
They require 22903 digit combinations to represent them.
1473 digit combinations represent textonyms.
269 -> amy any bmw bow box boy cow cox coy
729 -> paw pax pay paz raw ray saw sax say
Line 1,279 ⟶ 1,305:
426 -> gam gao ham han ian ibm ibn
25287876746242 -> claustrophobia claustrophobic
7244967473642 -> schizophrenia schizophrenic
|