this repo has no description
1module Millisecond01 where
2
3import Data.Char
4
5processDigitStr :: String -> Int
6processDigitStr str =
7 let pairs = zip str (tail str ++ [head str])
8 in sum . map (digitToInt . fst) . filter (uncurry (==)) $ pairs
9
10processDigitStr2 :: String -> Int
11processDigitStr2 str =
12 let halfStrLength = div (length str) 2
13 pairs = zip str ((drop halfStrLength str) ++ (take halfStrLength str))
14 in sum . map (digitToInt . fst) . filter (uncurry (==)) $ pairs
15
16main :: IO ()
17main = do
18 inputStr <- readFile "input.txt"
19 let input = init inputStr -- Drops the \n at the end
20 answer = processDigitStr2 input
21 in print answer