···21 let mut answer = 0
22 with readlines
23 |> it::map (parse rotation)
24- |> it::foldl rotate 50
25 when 'rotations(n) then {
26 answer += n
27 become unit
···21 let mut answer = 0
22 with readlines
23 |> it::map (parse rotation)
24+ |> it::fold rotate 50
25 when 'rotations(n) then {
26 answer += n
27 become unit
+46
2025/7/p1.tri
···0000000000000000000000000000000000000000000000
···1+import "trilogy:debug" use dbg
2+import "trilogy:io" use readlines
3+import "trilogy:string" use split, chomp
4+import "trilogy:number" use max, im, swap
5+import "trilogy:array" use map, reduce, length
6+import "trilogy:set" use push, contains, collect
7+import "trilogy:iterator" as it
8+9+proc collect_input!(it) {
10+ let mut start = unit
11+ let mut splitters = [||]
12+ with it!()
13+ when 'next(pos:'S') then {
14+ start = pos
15+ become unit
16+ }
17+ when 'next(pos:'^') then {
18+ push!(splitters, pos)
19+ become unit
20+ }
21+ when 'next(_) resume unit
22+ else yield
23+ return start:splitters
24+}
25+26+proc main!() {
27+ let start:splitters = collect_input!(
28+ readlines
29+ |> it::map (it::enumerate << it::from << chomp)
30+ |> it::enumerate
31+ |> it::flat_map (fn y:inner. it::map (fn x:v. x + y * 0i1 : v) inner)
32+ )
33+ let max_y = reduce max <| [swap <| im pos for pos in splitters]
34+ let mut splits = 0
35+ let mut i = 0
36+ let mut beams = [|start|]
37+ while i <= max_y {
38+ splits += length [beam for beam in beams and is contains beam splitters]
39+ beams = beams
40+ |> it::from
41+ |> it::flat_map (fn beam. if contains beam splitters then it::from [beam + 1i1, beam - 1 + 0i1] else it::of (beam + 0i1))
42+ |> collect
43+ i += 1
44+ }
45+ dbg!(splits)
46+}
+45
2025/7/p2.tri
···000000000000000000000000000000000000000000000
···1+import "trilogy:debug" use dbg
2+import "trilogy:io" use readlines
3+import "trilogy:string" use split, chomp
4+import "trilogy:number" use max, im, swap
5+import "trilogy:array" use map, reduce, length
6+import "trilogy:set" use push, contains, collect
7+import "trilogy:iterator" as it
8+9+proc collect_input!(it) {
10+ let mut start = unit
11+ let mut splitters = [||]
12+ with it!()
13+ when 'next(pos:'S') then {
14+ start = pos
15+ become unit
16+ }
17+ when 'next(pos:'^') then {
18+ push!(splitters, pos)
19+ become unit
20+ }
21+ when 'next(_) resume unit
22+ else yield
23+ return start:splitters
24+}
25+26+proc main!() {
27+ let start:splitters = collect_input!(
28+ readlines
29+ |> it::map (it::enumerate << it::from << chomp)
30+ |> it::enumerate
31+ |> it::flat_map (fn y:inner. it::map (fn x:v. x + y * 0i1 : v) inner)
32+ )
33+ let max_y = reduce max <| [swap <| im pos for pos in splitters]
34+ let mut splits = 0
35+ let mut i = 0
36+ let mut beams = {|start => 1|}
37+ while i <= max_y {
38+ beams = beams
39+ |> it::from
40+ |> it::flat_map (fn beam:val. if contains beam splitters then it::from [beam + 1i1: val, beam - 1 + 0i1: val] else it::of (beam + 0i1:val))
41+ |> it::fold (fn rec pos:val. {| ..rec, pos => val + with rec.pos when 'mia cancel 0 else yield |}) {||}
42+ i += 1
43+ }
44+ dbg!(reduce (+) [val for _:val in beams])
45+}