Advent of Code solutions

more pretty version of p1

+14 -15
+14 -15
2025/10/p1.tri
··· 4 4 import "trilogy:bits" as bits 5 5 import "trilogy:compare" use min 6 6 import "trilogy:parsec" use parse, apply, between, many_1, char_of, char, integer, sep_by_1 7 - import "trilogy:array" use map, fold, filter, reduce 7 + import "trilogy:array" use map, fold, filter, reduce, prepend 8 8 import "trilogy:set" use contains, difference, union, collect 9 9 import "trilogy:iterator" as it 10 10 ··· 33 33 return target:buttons 34 34 } 35 35 36 - proc solve!(target:buttons) { 37 - let mut visited = [| target ^ target |] 38 - let mut states = [| target ^ target |] 39 - let mut i = 0 40 - while !(contains target states) { 41 - let new_states = states 42 - |> it::from 43 - |> it::flat_map (fn state. it::from <| map ((^) state) buttons) 44 - |> collect 45 - states = difference new_states visited 46 - visited union= new_states 47 - i += 1 48 - } 49 - return i 36 + func choose 0 _ = do() yield 'next([]) 37 + func choose _ [] = do() {} 38 + func choose n [x, ..xs] = do() { 39 + let within = choose (n - 1) xs |> it::map (prepend x) 40 + let without = choose n xs 41 + within!() 42 + without!() 50 43 } 44 + 45 + func solve target:buttons = 46 + it::rangex 1 (length buttons) 47 + |> it::flat_map (fn n. choose n buttons) 48 + |> it::find (fn chosen. target == reduce (^) chosen) 49 + |> length 51 50 52 51 proc main!() { 53 52 readlines