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
implement p2 in trilogy now that its working!
eldridge.cam
3 months ago
531754bb
21344655
+34
1 changed file
expand all
collapse all
unified
split
2025
1
p2.tri
+34
2025/1/p2.tri
···
1
1
+
import "trilogy:debug" use dbg
2
2
+
import "trilogy:io" use readline
3
3
+
import "trilogy:number" use abs
4
4
+
import "trilogy:parsec" use parse, char_of, integer, apply
5
5
+
6
6
+
proc rotation!() {
7
7
+
let dir = apply <| char_of "LR"
8
8
+
let amt = apply integer
9
9
+
return if dir == 'R' then amt else -amt
10
10
+
}
11
11
+
12
12
+
func rotate pos amt =
13
13
+
if abs amt > 100
14
14
+
then yield 'full(abs amt // 100); rotate (amt % 100) pos
15
15
+
else pos + amt
16
16
+
17
17
+
proc main!() {
18
18
+
let mut zeros = 0
19
19
+
let mut pos = 50
20
20
+
while true {
21
21
+
pos = with rotate pos <| parse rotation readline!()
22
22
+
when 'eof cancel break unit
23
23
+
when 'full(n) then {
24
24
+
zeros += n
25
25
+
become unit
26
26
+
}
27
27
+
else yield
28
28
+
if pos < 0 || pos > 99 {
29
29
+
zeros += 1
30
30
+
pos = (pos + 100) % 100
31
31
+
}
32
32
+
}
33
33
+
dbg!(zeros)
34
34
+
}