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 6
eldridge.cam
3 months ago
579e7874
6223c181
+61
-1
3 changed files
expand all
collapse all
unified
split
2025
5
p1.tri
6
p1.tri
p2.tri
-1
2025/5/p1.tri
···
12
12
}
13
13
let ranges = apply <| per_line range
14
14
apply <| char '\n'
15
15
-
apply <| char '\n'
16
15
let items = apply <| per_line integer
17
16
return ranges : items
18
17
}
+22
2025/6/p1.tri
···
1
1
+
import "trilogy:debug" use dbg
2
2
+
import "trilogy:io" use readall
3
3
+
import "trilogy:parsec" use parse, many, many_1, char_of, sep_by, per_line, prefixed_by, followed_by, choice, integer, char
4
4
+
import "trilogy:array" use transpose, reduce, map
5
5
+
6
6
+
func calculate [..nums, '+'] = reduce (+) nums
7
7
+
func calculate [..nums, '*'] = reduce (*) nums
8
8
+
9
9
+
proc main!() {
10
10
+
let parser = per_line
11
11
+
<| followed_by (many <| char ' ')
12
12
+
<| prefixed_by (many <| char ' ')
13
13
+
<| sep_by (many_1 <| char ' ')
14
14
+
<| choice [integer, char_of "+*"]
15
15
+
dbg!(
16
16
+
readall!()
17
17
+
|> parse parser
18
18
+
|> transpose
19
19
+
|> map calculate
20
20
+
|> reduce (+)
21
21
+
)
22
22
+
}
+39
2025/6/p2.tri
···
1
1
+
import "trilogy:debug" use dbg
2
2
+
import "trilogy:io" use readall
3
3
+
import "trilogy:parsec" use parse, many, many_1, char_of, sep_by, per_line, prefixed_by, followed_by, integer, char, apply, option
4
4
+
import "trilogy:array" use transpose, reduce, map, flatten, reverse
5
5
+
import "trilogy:string" use split, chars, join
6
6
+
7
7
+
func calculate [..nums, '+'] = reduce (+) nums
8
8
+
func calculate [..nums, '*'] = reduce (*) nums
9
9
+
10
10
+
proc row!() {
11
11
+
apply <| many <| char ' '
12
12
+
let n = apply integer
13
13
+
apply <| many <| char ' '
14
14
+
return match apply <| option <| char_of "+*"
15
15
+
case 'some(ch) then [n, ch]
16
16
+
else then [n]
17
17
+
}
18
18
+
19
19
+
proc blank!() {
20
20
+
apply <| many_1 <| char ' '
21
21
+
apply <| char '\n'
22
22
+
}
23
23
+
24
24
+
proc main!() {
25
25
+
let parser = sep_by blank <| per_line row
26
26
+
dbg!(
27
27
+
readall!()
28
28
+
|> split "\n"
29
29
+
|> map chars
30
30
+
|> transpose
31
31
+
|> map (join "")
32
32
+
|> reverse
33
33
+
|> join "\n"
34
34
+
|> parse parser
35
35
+
|> map flatten
36
36
+
|> map calculate
37
37
+
|> reduce (+)
38
38
+
)
39
39
+
}