Textonyms: Difference between revisions
Content deleted Content added
→{{header|C++}}: minor modifications |
m →{{header|Haskell}}: Tidied |
||
Line 1,124:
Or, in terms of ''Data.Map'' and ''traverse'':
<lang haskell>import Data.
import Data.List (groupBy, maximum, sortBy, sortOn)
import qualified Data.Map as M
import Data.Maybe (mapMaybe)
import Data.Ord (comparing)
------------------------ TEXTONYMS -----------------------
digitEncoded :: M.Map Char Char -> [String] -> [(String, String)]
digitEncoded dict =
mapMaybe $
((>>=) . traverse (`M.lookup` dict))
<*> curry Just
charDict :: M.Map Char Char
charDict =
M.fromList $
concat $
zipWith
(fmap . flip (,))
(head . show <$> [2 ..])
(words "abc def ghi jkl mno pqrs tuv wxyz")
definedSamples ::
definedSamples n xs fs =
[take n . flip sortBy xs] <*> (flip . comparing <$> fs)
--------------------------- TEST
main :: IO ()
main = do
Line 1,160 ⟶ 1,165:
mapM_
putStrLn
[ "There are "
<> show (length encodings)
<> " words in "
<> fp
show (length codeGroups) ++ " digit combinations to represent them."▼
<> " digit combinations to represent them.",
, ""▼
]
let codeLength = length . snd . head
Line 1,174 ⟶ 1,181:
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 [rjust w ' ' (snd (head ts)), " -> ", unwords $ fmap fst ts]
where
rjust n c = (drop . length) <*> (replicate n c
{{Out}}
<pre>There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
|