···90909191func key grid = fold (fn a b. $"${a}${str::cast b}") "" <| do() $(ch for line in grid and (ch in line or ch = '\n'))
92929393-const target = 1000000000
9393+slot target = 1000000000
94949595proc main!() {
9696 let mut total = 0
+7-7
2023/17/p1.tri
···55module tuple at "trilogy:tuple" use fst, snd
66module btreemod at "trilogy:btree" use btree
7788-const N = -0i1
99-const S = 0i1
1010-const E = 1i0
1111-const W = -1i0
88+slot N = -1i
99+slot S = 1i
1010+slot E = 1
1111+slot W = -1
12121313-func turn dir = [-0i1 * dir, -(-0i1 * dir)]
1313+func turn dir = [-1i * dir, -(-1i * dir)]
1414func key ^N = 'v
1515func key ^S = 'v
1616func key ^E = 'h
···24242525proc main!() {
2626 let grid = [[cast $"${n}"fmt for n in chars <| chomp line] for line in readlines!()]
2727- let best = {| 0i0 => {| 'h => 0, 'v => 0 |} |}
2727+ let best = {| 0 => {| 'h => 0, 'v => 0 |} |}
28282929 let goal = (length grid * S + length (grid.0) * E) + N + W
3030···33333434 let ltree = btree (asc score)
35353636- let mut queue = ltree::from [0i0:E, 0i0:S]
3636+ let mut queue = ltree::from [0:E, 0:S]
3737 while queue != 'empty {
3838 let (pos:face):q2 = ltree::pop_min queue
3939 queue = q2
+7-7
2023/17/p2.tri
···66module btreemod at "trilogy:btree" use btree
77module iter at "trilogy:iter" use range
8899-const N = -0i1
1010-const S = 0i1
1111-const E = 1i0
1212-const W = -1i0
99+slot N = -1i
1010+slot S = 1i
1111+slot E = 1
1212+slot W = -1
13131414-func turn dir = [-0i1 * dir, -(-0i1 * dir)]
1414+func turn dir = [-1i * dir, -(-1i * dir)]
1515func key ^N = 'v
1616func key ^S = 'v
1717func key ^E = 'h
···25252626proc main!() {
2727 let grid = [[cast $"${n}"fmt for n in chars <| chomp line] for line in readlines!()]
2828- let best = {| 0i0 => {| 'h => 0, 'v => 0 |} |}
2828+ let best = {| 0 => {| 'h => 0, 'v => 0 |} |}
29293030 let goal = (length grid * S + length (grid.0) * E) + N + W
3131···34343535 let ltree = btree (asc score)
36363737- let mut queue = ltree::from [0i0:E, 0i0:S]
3737+ let mut queue = ltree::from [0:E, 0:S]
3838 while queue != 'empty {
3939 let (pos:face):q2 = ltree::pop_min queue
4040 queue = q2
+6-6
2023/18/p1.tri
···66module array at "trilogy:array" use fold, map, flatmap, length, filter
77module iter at "trilogy:iter" use repeat, collect, range, rangex, of
8899-const line_regex = regex::new "([LRUD]) (\\d+) \\(#([a-f0-9]{6})\\)"
99+slot line_regex = regex::new "([LRUD]) (\\d+) \\(#([a-f0-9]{6})\\)"
10101111func scan f i [] = [i]
1212func scan f i [x, ..xs] = let a = f i x, [a, ..scan f a xs]
13131414-const L = -1
1515-const R = 1
1616-const U = -0i1
1717-const D = 0i1
1414+slot L = -1
1515+slot R = 1
1616+slot U = -1i
1717+slot D = 1i
18181919func delta "L" = L
2020func delta "R" = R
···35353636proc main!() {
3737 let instructions = [d:cast n:c for line in readlines!() and {| 1 => d, 2 => n, 3 => c, .._ |} = line_regex::matches line]
3838- let coords = scan move 0i0 instructions
3838+ let coords = scan move 0 instructions
3939 let min_x = fold min 0 <| map re coords
4040 let max_x = fold max 0 <| map re coords
4141 let min_y = fold min 0 <| map im coords
+6-6
2023/18/p2.tri
···66module array at "trilogy:array" use fold, map, flatmap, length, filter, sort, position
77module iter at "trilogy:iter" use repeat, collect, range, rangex, of
8899-const line_regex = regex::new "([LRUD]) (\\d+) \\(#([a-f0-9]{6})\\)"
99+slot line_regex = regex::new "([LRUD]) (\\d+) \\(#([a-f0-9]{6})\\)"
10101111func scan f i [] = [i]
1212func scan f i [x, ..xs] = let a = f i x, [a, ..scan f a xs]
13131414-const L = -1
1515-const R = 1
1616-const U = -0i1
1717-const D = 0i1
1414+slot L = -1
1515+slot R = 1
1616+slot U = -1i
1717+slot D = 1i
18181919func delta "L" = L
2020func delta "R" = R
···44444545proc main!() {
4646 let instructions = [parse c for line in readlines!() and {| 3 => c, .._ |} = line_regex::matches line]
4747- let coords = scan move 0i0 instructions
4747+ let coords = scan move 0 instructions
4848 let xs = sort (<=) [x for x in [| re coord for coord in coords |]]
4949 let ys = sort (<=) [y for y in [| im coord for coord in coords |]]
5050
+2-2
2023/19/p1.tri
···44module str at "trilogy:str" use chomp, split
55module regex at "trilogy:regex"
6677-const workflow_regex = regex::new "(?<name>\\w+)\\{(?<steps>.*)\\}"
88-const step_regex = regex::new "(?<comp>[xmas])(?<op>[<>])(?<val>\\d+)"
77+slot workflow_regex = regex::new "(?<name>\\w+)\\{(?<steps>.*)\\}"
88+slot step_regex = regex::new "(?<comp>[xmas])(?<op>[<>])(?<val>\\d+)"
991010func always x _ = x
1111
+2-2
2023/19/p2.tri
···55module range at "trilogy:range" use overlap, length, new
66module regex at "trilogy:regex"
7788-const workflow_regex = regex::new "(?<name>\\w+)\\{(?<steps>.*)\\}"
99-const step_regex = regex::new "(?<comp>[xmas])(?<op>[<>])(?<val>\\d+)"
88+slot workflow_regex = regex::new "(?<name>\\w+)\\{(?<steps>.*)\\}"
99+slot step_regex = regex::new "(?<comp>[xmas])(?<op>[<>])(?<val>\\d+)"
10101111func comp_total comp = length comp
1212func part_total {| "x" => x, "m" => m, "a" => a, "s" => s |} = comp_total x * comp_total m * comp_total a * comp_total s
···2525}
26262727module flipflop destinations {
2828- const state = {| 'on => false |}
2828+ slot state = {| 'on => false |}
29293030 proc add_input!(_) {}
3131···5757}
58585959module conjunction destinations {
6060- const state = {||}
6060+ slot state = {||}
61616262 proc add_input!(input) {
6363 state.input = 'low
···9393 export add_input, init, signal
9494}
95959696-const important = ["mp", "qt", "qb", "ng"]
9696+slot important = ["mp", "qt", "qb", "ng"]
97979898func parse_node srcdest = let [name, dests] = split " -> " srcdest, name : split ", " dests
9999
+4-4
2023/21/p1.tri
···55module record at "trilogy:record" use values
66module iter at "trilogy:iter" use count, filter, rangex
7788-const N = -0i1
99-const S = 0i1
1010-const E = 1
1111-const W = -1
88+slot N = -1i
99+slot S = 1i
1010+slot E = 1
1111+slot W = -1
12121313func get pos grid = with grid.(im pos).(re pos) else cancel '#'
1414func adj pos = $(d + pos for d in [N, S, E, W])
+4-4
2023/21/p2.tri
···55module record at "trilogy:record" use values
66module iter at "trilogy:iter" use count, filter, rangex
7788-const N = -0i1
99-const S = 0i1
1010-const E = 1
1111-const W = -1
88+slot N = -1i
99+slot S = 1i
1010+slot E = 1
1111+slot W = -1
12121313func get pos grid = with grid.(im pos).(re pos) else cancel '#'
1414func adj pos = $(d + pos for d in [N, S, E, W])
+1-1
2023/22/p1.tri
···77module regex at "trilogy:regex"
88module iter at "trilogy:iter" use range
991010-const line_regex = regex::new "(\\d+),(\\d+),(\\d+)~(\\d+),(\\d+),(\\d+)"
1010+slot line_regex = regex::new "(\\d+),(\\d+),(\\d+)~(\\d+),(\\d+),(\\d+)"
1111func parse str =
1212 let matches = line_regex::matches str,
1313 normalize (cast (matches.1):cast (matches.2):cast (matches.3)) (cast (matches.4):cast (matches.5):cast (matches.6))
+1-1
2023/22/p2.tri
···77module regex at "trilogy:regex"
88module iter at "trilogy:iter" use range
991010-const line_regex = regex::new "(\\d+),(\\d+),(\\d+)~(\\d+),(\\d+),(\\d+)"
1010+slot line_regex = regex::new "(\\d+),(\\d+),(\\d+)~(\\d+),(\\d+),(\\d+)"
1111func parse str =
1212 let matches = line_regex::matches str,
1313 normalize (cast (matches.1):cast (matches.2):cast (matches.3)) (cast (matches.4):cast (matches.5):cast (matches.6))
+4-4
2023/23/p1.tri
···55module set at "trilogy:set" use contains, length
66module tuple at "trilogy:tuple" use fst
7788-const N = -0i1
99-const S = 0i1
1010-const E = 1
1111-const W = -1
88+slot N = -1i
99+slot S = 1i
1010+slot E = 1
1111+slot W = -1
12121313func walkable ^E '>' = true
1414func walkable ^W '<' = true
+4-4
2023/23/p2.tri
···66module record at "trilogy:record"
77module tuple at "trilogy:tuple" use fst
8899-const N = -0i1
1010-const S = 0i1
1111-const E = 1
1212-const W = -1
99+slot N = -1i
1010+slot S = 1i
1111+slot E = 1
1212+slot W = -1
13131414func walkable '#' = false
1515func walkable _ = true
···66module set at "trilogy:set" use intersection, length
77module array at "trilogy:array"
8899-const card_regex = regex::new "Card\\s+\\d+:([^|]+)\\|([^|]+)"
99+slot card_regex = regex::new "Card\\s+\\d+:([^|]+)\\|([^|]+)"
10101111func parse_nums numstr = [| num::cast x for x in numstr |> split " " and is x != "" |]
1212func parse_card card = parse_nums card.1 : parse_nums card.2
+1-1
2023/4/p2.tri
···66module set at "trilogy:set" use intersection, length
77module array at "trilogy:array" use fold
8899-const card_regex = regex::new "Card\\s+\\d+:([^|]+)\\|([^|]+)"
99+slot card_regex = regex::new "Card\\s+\\d+:([^|]+)\\|([^|]+)"
10101111func parse_nums numstr = [| num::cast x for x in numstr |> split " " and is x != "" |]
1212func parse_card card = parse_nums card.1 : parse_nums card.2
+1-1
2023/5/p1.tri
···66module record at "trilogy:record"
77module iter at "trilogy:iter" use collect, of
8899-const heading_regex = regex::new "(\\w+)-to-(\\w+) map:"
99+slot heading_regex = regex::new "(\\w+)-to-(\\w+) map:"
1010func parse_section [heading, ..ranges] =
1111 let {| 1 => from, 2 => to, .._ |} = heading_regex::matches heading,
1212 let parsed_ranges = map (str::split " " >> map cast) ranges,