Advent of Code solutions

2025 day 8 but i did it yesterday and forgot to commmit

+56 -9
+10 -9
2025/8/p1.tri
··· 1 1 import "trilogy:debug" use dbg 2 2 import "trilogy:io" use readlines 3 3 import "trilogy:parsec" use parse, sep_by, char, integer, per_line 4 - import "trilogy:array" use push, collect, sort_by, take, reduce 4 + import "trilogy:array" use collect, sort_by, take, reduce 5 5 import "trilogy:core" use length 6 6 import "trilogy:iterator" as it 7 7 import "trilogy:set" use union 8 + import "trilogy:heap" use heap 8 9 9 10 func dist [x1, y1, z1]:[x2, y2, z2] = (x1-x2)**2 + (y1-y2)**2 + (z1-z2)**2 10 - func dist_asc a b = dist a < dist b 11 + func dist_asc a b = dist a <= dist b 11 12 12 13 proc main!() { 13 14 let points = readlines 14 15 |> it::map (parse (sep_by (char ',') integer)) 15 16 |> collect 16 17 18 + let edge_heap = heap dist_asc 19 + 17 20 let mut edges = [] 18 21 let mut i = 0 19 22 while i < length points { 20 23 let mut j = i + 1 21 24 while j < length points { 22 - push!(edges, points.i:points.j) 25 + edge_heap::push!(edges, points.i:points.j) 23 26 j += 1 24 27 } 25 28 i += 1 26 29 } 27 - dbg!(length edges) 28 - edges sort_by= dist_asc 29 - dbg!("sorted") 30 - edges take= 1000 31 - dbg!("taken") 32 30 33 31 let mut sets = {| pos => [| pos |] for pos in points |} 34 - for a:b in edges { 32 + let mut i = 0 33 + while i < 1000 { 34 + i += 1 35 + let a:b = edge_heap::pop!(edges) 35 36 sets.a union= sets.b 36 37 for el in sets.a { 37 38 sets.el = sets.a
+46
2025/8/p2.tri
··· 1 + import "trilogy:debug" use dbg 2 + import "trilogy:io" use readlines 3 + import "trilogy:parsec" use parse, sep_by, char, integer, per_line 4 + import "trilogy:array" use collect 5 + import "trilogy:core" use length 6 + import "trilogy:iterator" as it 7 + import "trilogy:set" use union 8 + import "trilogy:heap" use heap 9 + 10 + func dist [x1, y1, z1]:[x2, y2, z2] = (x1-x2)**2 + (y1-y2)**2 + (z1-z2)**2 11 + func dist_asc a b = dist a <= dist b 12 + 13 + proc main!() { 14 + let points = readlines 15 + |> it::map (parse (sep_by (char ',') integer)) 16 + |> collect 17 + 18 + let edge_heap = heap dist_asc 19 + 20 + let mut edges = [] 21 + let mut i = 0 22 + while i < length points { 23 + let mut j = i + 1 24 + while j < length points { 25 + edge_heap::push!(edges, points.i:points.j) 26 + j += 1 27 + } 28 + i += 1 29 + } 30 + 31 + let mut sets = {| pos => [| pos |] for pos in points |} 32 + let mut i = 0 33 + while length edges > 0 { 34 + i += 1 35 + let a:b = edge_heap::pop!(edges) 36 + if sets.a == sets.b { continue unit } 37 + sets.a union= sets.b 38 + if length (sets.a) == length points { 39 + dbg!(a.0 * b.0) 40 + return 0 41 + } 42 + for el in sets.a { # NOTE: this for loop is the slowest part... 43 + sets.el = sets.a 44 + } 45 + } 46 + }