1 input = "11100010111110100"
14 part1 = print $ fill disk1length input
17 part2 = print $ fill disk2length input
19 fill :: Int -> String -> String
20 fill len filler = deBool $ checksum $ take len $ expand len $ enBool filler
22 enBool :: String -> [Bool]
25 deBool :: [Bool] -> String
26 deBool = map (\b -> if b then '1' else '0')
29 expand :: Int -> [Bool] -> [Bool]
30 expand len = head . dropWhile ((<= len) . length) . iterate expandStep
32 expandStep :: [Bool] -> [Bool]
33 expandStep a = a ++ [False] ++ b
34 where b = map (not) $ reverse a
36 checksum :: [Bool] -> [Bool]
37 checksum = head . dropWhile (even . length) . iterate checksumStep
39 checksumStep :: [Bool] -> [Bool]
41 checksumStep [x] = [x]
42 checksumStep (x:y:xs) = (x==y):(checksumStep xs)