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