Advent of Code 2025
1module Day1 where
2
3parseLine :: String -> (Char, Int)
4parseLine (c : s) = (c, read s)
5
6parseInput :: String -> [(Char,Int)]
7parseInput input = map parseLine $ lines input
8
9doRotations :: [(Char, Int)] -> Int -> [Int]
10doRotations (('L', l) : rest) n = (n : doRotations rest ((n-l) `mod` 100))
11doRotations (('R', r) : rest) n = (n : doRotations rest ((n+r) `mod` 100))
12doRotations [] n = [n]
13
14getCrossings :: [(Char, Int)] -> Int -> [Int]
15getCrossings (('L', l) : rest) n = (((l-n) `div` 100) + (if n > 0 then 1 else 0) : getCrossings rest ((n-l) `mod` 100))
16getCrossings (('R', r) : rest) n = (((n+r) `div` 100) : getCrossings rest ((n+r) `mod` 100))
17getCrossings [] _ = []
18
19part1 :: String -> String
20part1 input =
21 let rotations = parseInput input
22 states = doRotations rotations 50
23 in show $ length (filter (== 0) states)
24
25part2 :: String -> String
26part2 input =
27 let rotations = parseInput input
28 zeroCrossings = getCrossings rotations 50
29 in show $ sum zeroCrossings