Advent of Code solutions

2025 day 6

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