module Day1 where parseLine :: String -> (Char, Int) parseLine (c : s) = (c, read s) parseInput :: String -> [(Char,Int)] parseInput input = map parseLine $ lines input doRotations :: [(Char, Int)] -> Int -> [Int] doRotations (('L', l) : rest) n = (n : doRotations rest ((n-l) `mod` 100)) doRotations (('R', r) : rest) n = (n : doRotations rest ((n+r) `mod` 100)) doRotations [] n = [n] getCrossings :: [(Char, Int)] -> Int -> [Int] getCrossings (('L', l) : rest) n = (((l-n) `div` 100) + (if n > 0 then 1 else 0) : getCrossings rest ((n-l) `mod` 100)) getCrossings (('R', r) : rest) n = (((n+r) `div` 100) : getCrossings rest ((n+r) `mod` 100)) getCrossings [] _ = [] part1 :: String -> String part1 input = let rotations = parseInput input states = doRotations rotations 50 in show $ length (filter (== 0) states) part2 :: String -> String part2 input = let rotations = parseInput input zeroCrossings = getCrossings rotations 50 in show $ sum zeroCrossings