1 module Main(main) where
3 input = "11100010111110100"
16 part1 = print $ fill disk1length input
19 part2 = print $ fill disk2length input
21 fill :: Int -> String -> String
22 fill len filler = deBool $ checksum $ take len $ expand len $ enBool filler
24 enBool :: String -> [Bool]
27 deBool :: [Bool] -> String
28 deBool = map (\b -> if b then '1' else '0')
31 expand :: Int -> [Bool] -> [Bool]
32 expand len = head . dropWhile ((<= len) . length) . iterate expandStep
34 expandStep :: [Bool] -> [Bool]
35 expandStep a = a ++ [False] ++ b
36 where b = map (not) $ reverse a
38 checksum :: [Bool] -> [Bool]
39 checksum = head . dropWhile (even . length) . iterate checksumStep
41 checksumStep :: [Bool] -> [Bool]
43 checksumStep [x] = [x]
44 checksumStep (x:y:xs) = (x==y):(checksumStep xs)