tangled
alpha
login
or
join now
eldridge.cam
/
advent-of-code
2
fork
atom
Advent of Code solutions
2
fork
atom
overview
issues
pulls
pipelines
2025 day 1
eldridge.cam
3 months ago
34e6e179
d652d500
+15
2 changed files
expand all
collapse all
unified
split
2025
1
p1.hs
p2.hs
+4
2025/1/p1.hs
···
1
1
+
rotate rot ('L' : dist) = (rot - (read dist `mod` 100) + 100) `mod` 100
2
2
+
rotate rot ('R' : dist) = (rot + read dist) `mod` 100
3
3
+
4
4
+
main = getContents >>= print . length . filter ((==) 0) . scanl rotate 50 . lines
+11
2025/1/p2.hs
···
1
1
+
rotate (count, rot) ('L' : dist) = rotate_ count rot (-read dist)
2
2
+
rotate (count, rot) ('R' : dist) = rotate_ count rot (read dist)
3
3
+
4
4
+
rotate_ count rot dist = (count2, rot2)
5
5
+
where
6
6
+
rotations = abs dist `div` 100
7
7
+
crossed = not $ (rot + dist `rem` 100) `elem` [0 .. 99]
8
8
+
count2 = count + rotations + if crossed then 1 else 0
9
9
+
rot2 = (rot + (dist `rem` 100) + 100) `rem` 100
10
10
+
11
11
+
main = getContents >>= print . fst . foldl rotate (0, 50) . lines