Advent of Code solutions

2025 day 3

+59
+27
2025/3/p1.tri
··· 1 + import "trilogy:debug" use dbg 2 + import "trilogy:io" use readlines 3 + import "trilogy:string" use chars, chomp 4 + import "trilogy:number" use from_digit 5 + import "trilogy:iterator" as it 6 + import "trilogy:array" as arr 7 + 8 + func run_joltage (a : b) [only] = if only > b then a:only else a:b 9 + func run_joltage (a : b) [head, ..rest] = 10 + if head > a then run_joltage (head:0) rest 11 + else if head > b then run_joltage (a:head) rest 12 + else run_joltage (a:b) rest 13 + 14 + func joltage digits = run_joltage (0:0) digits 15 + 16 + proc main!() { 17 + let total = readlines 18 + |> it::map ( 19 + chomp 20 + >> chars 21 + >> arr::map from_digit 22 + >> joltage 23 + >> fn a:b. a * 10 + b 24 + ) 25 + |> it::sum 26 + dbg!(total) 27 + }
+32
2025/3/p2.tri
··· 1 + import "trilogy:debug" use dbg 2 + import "trilogy:io" use readlines 3 + import "trilogy:string" use chars, chomp 4 + import "trilogy:number" use from_digit, max 5 + import "trilogy:iterator" as it 6 + import "trilogy:array" as arr use take, skip 7 + 8 + func update_state state offset digit = 9 + let len = arr::length state, 10 + if offset >= len then state 11 + else if state.offset < digit then [..take offset state, digit, ..arr::collect <| it::repeat (len - offset - 1) 0] 12 + else update_state state (offset + 1) digit 13 + 14 + func run_joltage state [] = state 15 + func run_joltage state [head, ..rest] = 16 + let limit = max ((arr::length state) - (arr::length rest) - 1) 0, 17 + run_joltage (update_state state limit head) rest 18 + 19 + func joltage digits = run_joltage [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] digits 20 + 21 + proc main!() { 22 + let total = readlines 23 + |> it::map ( 24 + chomp 25 + >> chars 26 + >> arr::map from_digit 27 + >> joltage 28 + >> arr::fold (fn a b. a * 10 + b) 0 29 + ) 30 + |> it::sum 31 + dbg!(total) 32 + }