-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06.hs
26 lines (20 loc) · 765 Bytes
/
06.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import Text.ParserCombinators.Parsec
import Data.List
file :: Parser [String]
file = many1 $ do
line <- many1 lower
newline
return line
frequencies :: String -> [(Int, Char)]
frequencies s = [(length c, c !! 0) | c <- group (sort s)]
mostFrequentLetter :: String -> Char
mostFrequentLetter = snd . maximum . frequencies
leastFrequentLetter :: String -> Char
leastFrequentLetter = snd . minimum . frequencies
decodeWith :: (String -> Char) -> [String] -> String
decodeWith f = map f . transpose
main = do
input <- getContents
let dat = parse file "" input
putStrLn . show $ (decodeWith mostFrequentLetter) <$> dat
putStrLn . show $ (decodeWith leastFrequentLetter) <$> dat