1 module Main(main) where
5 input = "11100010111110100"
18 part1 = putStrLn $ checksum $ take disk1length $ expand disk1length input
21 part2 = putStrLn $ checksum $ take disk2length $ expand disk2length input
24 expand :: Int -> String -> String
27 | otherwise = expand len $ a ++ "0" ++ b
28 where b = map (invert) $ reverse a
32 checksum :: String -> String
34 | odd $ length digits = digits
35 | otherwise = checksum $ map (checksumPair) $ pairs digits
36 where checksumPair p = if (length $ nub p) == 1 then '1' else '0'
41 pairs xs = [p] ++ (pairs ys)
42 where (p, ys) = splitAt 2 xs