- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
by :: Int -> [a] -> [[a]]
by _ [] = []
by n xs = take n xs: by n (drop n xs)
words2 :: String -> (String, String)
words2 str = conc $ words str where
conc (x:xs) = (x, concat xs)
groupTemplates :: String -> [(String, String)]
groupTemplates xs = map (words2) (lines xs)
decodeOne :: String -> [(String, String)] -> String
decodeOne _ [] = ""
decodeOne str (x:xs) | str == fst x = fst x ++ " " ++ snd x ++ "\n"
decodeOne str (_:xs) = decodeOne str xs
decode :: [String] -> [(String, String)] -> String
decode bs ts = concat $ map (\b -> decodeOne b ts) bs
main = do
bits <- readFile "bits.txt"
templates <- readFile "templates.txt"
writeFile "out.txt" $ decode (by 4 bits) (groupTemplates templates)