···9091func key grid = fold (fn a b. $"${a}${str::cast b}") "" <| do() $(ch for line in grid and (ch in line or ch = '\n'))
9293-const target = 1000000000
9495proc main!() {
96 let mut total = 0
···9091func key grid = fold (fn a b. $"${a}${str::cast b}") "" <| do() $(ch for line in grid and (ch in line or ch = '\n'))
9293+slot target = 1000000000
9495proc main!() {
96 let mut total = 0
+7-7
2023/17/p1.tri
···5module tuple at "trilogy:tuple" use fst, snd
6module btreemod at "trilogy:btree" use btree
78-const N = -0i1
9-const S = 0i1
10-const E = 1i0
11-const W = -1i0
1213-func turn dir = [-0i1 * dir, -(-0i1 * dir)]
14func key ^N = 'v
15func key ^S = 'v
16func key ^E = 'h
···2425proc main!() {
26 let grid = [[cast $"${n}"fmt for n in chars <| chomp line] for line in readlines!()]
27- let best = {| 0i0 => {| 'h => 0, 'v => 0 |} |}
2829 let goal = (length grid * S + length (grid.0) * E) + N + W
30···3334 let ltree = btree (asc score)
3536- let mut queue = ltree::from [0i0:E, 0i0:S]
37 while queue != 'empty {
38 let (pos:face):q2 = ltree::pop_min queue
39 queue = q2
···5module tuple at "trilogy:tuple" use fst, snd
6module btreemod at "trilogy:btree" use btree
78+slot N = -1i
9+slot S = 1i
10+slot E = 1
11+slot W = -1
1213+func turn dir = [-1i * dir, -(-1i * dir)]
14func key ^N = 'v
15func key ^S = 'v
16func key ^E = 'h
···2425proc main!() {
26 let grid = [[cast $"${n}"fmt for n in chars <| chomp line] for line in readlines!()]
27+ let best = {| 0 => {| 'h => 0, 'v => 0 |} |}
2829 let goal = (length grid * S + length (grid.0) * E) + N + W
30···3334 let ltree = btree (asc score)
3536+ let mut queue = ltree::from [0:E, 0:S]
37 while queue != 'empty {
38 let (pos:face):q2 = ltree::pop_min queue
39 queue = q2
+7-7
2023/17/p2.tri
···6module btreemod at "trilogy:btree" use btree
7module iter at "trilogy:iter" use range
89-const N = -0i1
10-const S = 0i1
11-const E = 1i0
12-const W = -1i0
1314-func turn dir = [-0i1 * dir, -(-0i1 * dir)]
15func key ^N = 'v
16func key ^S = 'v
17func key ^E = 'h
···2526proc main!() {
27 let grid = [[cast $"${n}"fmt for n in chars <| chomp line] for line in readlines!()]
28- let best = {| 0i0 => {| 'h => 0, 'v => 0 |} |}
2930 let goal = (length grid * S + length (grid.0) * E) + N + W
31···3435 let ltree = btree (asc score)
3637- let mut queue = ltree::from [0i0:E, 0i0:S]
38 while queue != 'empty {
39 let (pos:face):q2 = ltree::pop_min queue
40 queue = q2
···6module btreemod at "trilogy:btree" use btree
7module iter at "trilogy:iter" use range
89+slot N = -1i
10+slot S = 1i
11+slot E = 1
12+slot W = -1
1314+func turn dir = [-1i * dir, -(-1i * dir)]
15func key ^N = 'v
16func key ^S = 'v
17func key ^E = 'h
···2526proc main!() {
27 let grid = [[cast $"${n}"fmt for n in chars <| chomp line] for line in readlines!()]
28+ let best = {| 0 => {| 'h => 0, 'v => 0 |} |}
2930 let goal = (length grid * S + length (grid.0) * E) + N + W
31···3435 let ltree = btree (asc score)
3637+ let mut queue = ltree::from [0:E, 0:S]
38 while queue != 'empty {
39 let (pos:face):q2 = ltree::pop_min queue
40 queue = q2
+6-6
2023/18/p1.tri
···6module array at "trilogy:array" use fold, map, flatmap, length, filter
7module iter at "trilogy:iter" use repeat, collect, range, rangex, of
89-const line_regex = regex::new "([LRUD]) (\\d+) \\(#([a-f0-9]{6})\\)"
1011func scan f i [] = [i]
12func scan f i [x, ..xs] = let a = f i x, [a, ..scan f a xs]
1314-const L = -1
15-const R = 1
16-const U = -0i1
17-const D = 0i1
1819func delta "L" = L
20func delta "R" = R
···3536proc main!() {
37 let instructions = [d:cast n:c for line in readlines!() and {| 1 => d, 2 => n, 3 => c, .._ |} = line_regex::matches line]
38- let coords = scan move 0i0 instructions
39 let min_x = fold min 0 <| map re coords
40 let max_x = fold max 0 <| map re coords
41 let min_y = fold min 0 <| map im coords
···6module array at "trilogy:array" use fold, map, flatmap, length, filter
7module iter at "trilogy:iter" use repeat, collect, range, rangex, of
89+slot line_regex = regex::new "([LRUD]) (\\d+) \\(#([a-f0-9]{6})\\)"
1011func scan f i [] = [i]
12func scan f i [x, ..xs] = let a = f i x, [a, ..scan f a xs]
1314+slot L = -1
15+slot R = 1
16+slot U = -1i
17+slot D = 1i
1819func delta "L" = L
20func delta "R" = R
···3536proc main!() {
37 let instructions = [d:cast n:c for line in readlines!() and {| 1 => d, 2 => n, 3 => c, .._ |} = line_regex::matches line]
38+ let coords = scan move 0 instructions
39 let min_x = fold min 0 <| map re coords
40 let max_x = fold max 0 <| map re coords
41 let min_y = fold min 0 <| map im coords
+6-6
2023/18/p2.tri
···6module array at "trilogy:array" use fold, map, flatmap, length, filter, sort, position
7module iter at "trilogy:iter" use repeat, collect, range, rangex, of
89-const line_regex = regex::new "([LRUD]) (\\d+) \\(#([a-f0-9]{6})\\)"
1011func scan f i [] = [i]
12func scan f i [x, ..xs] = let a = f i x, [a, ..scan f a xs]
1314-const L = -1
15-const R = 1
16-const U = -0i1
17-const D = 0i1
1819func delta "L" = L
20func delta "R" = R
···4445proc main!() {
46 let instructions = [parse c for line in readlines!() and {| 3 => c, .._ |} = line_regex::matches line]
47- let coords = scan move 0i0 instructions
48 let xs = sort (<=) [x for x in [| re coord for coord in coords |]]
49 let ys = sort (<=) [y for y in [| im coord for coord in coords |]]
50
···6module array at "trilogy:array" use fold, map, flatmap, length, filter, sort, position
7module iter at "trilogy:iter" use repeat, collect, range, rangex, of
89+slot line_regex = regex::new "([LRUD]) (\\d+) \\(#([a-f0-9]{6})\\)"
1011func scan f i [] = [i]
12func scan f i [x, ..xs] = let a = f i x, [a, ..scan f a xs]
1314+slot L = -1
15+slot R = 1
16+slot U = -1i
17+slot D = 1i
1819func delta "L" = L
20func delta "R" = R
···4445proc main!() {
46 let instructions = [parse c for line in readlines!() and {| 3 => c, .._ |} = line_regex::matches line]
47+ let coords = scan move 0 instructions
48 let xs = sort (<=) [x for x in [| re coord for coord in coords |]]
49 let ys = sort (<=) [y for y in [| im coord for coord in coords |]]
50
+2-2
2023/19/p1.tri
···4module str at "trilogy:str" use chomp, split
5module regex at "trilogy:regex"
67-const workflow_regex = regex::new "(?<name>\\w+)\\{(?<steps>.*)\\}"
8-const step_regex = regex::new "(?<comp>[xmas])(?<op>[<>])(?<val>\\d+)"
910func always x _ = x
11
···4module str at "trilogy:str" use chomp, split
5module regex at "trilogy:regex"
67+slot workflow_regex = regex::new "(?<name>\\w+)\\{(?<steps>.*)\\}"
8+slot step_regex = regex::new "(?<comp>[xmas])(?<op>[<>])(?<val>\\d+)"
910func always x _ = x
11
+2-2
2023/19/p2.tri
···5module range at "trilogy:range" use overlap, length, new
6module regex at "trilogy:regex"
78-const workflow_regex = regex::new "(?<name>\\w+)\\{(?<steps>.*)\\}"
9-const step_regex = regex::new "(?<comp>[xmas])(?<op>[<>])(?<val>\\d+)"
1011func comp_total comp = length comp
12func part_total {| "x" => x, "m" => m, "a" => a, "s" => s |} = comp_total x * comp_total m * comp_total a * comp_total s
···5module range at "trilogy:range" use overlap, length, new
6module regex at "trilogy:regex"
78+slot workflow_regex = regex::new "(?<name>\\w+)\\{(?<steps>.*)\\}"
9+slot step_regex = regex::new "(?<comp>[xmas])(?<op>[<>])(?<val>\\d+)"
1011func comp_total comp = length comp
12func part_total {| "x" => x, "m" => m, "a" => a, "s" => s |} = comp_total x * comp_total m * comp_total a * comp_total s
+1-1
2023/2/p2.tri
···4module array at "trilogy:array" use map, flatmap, fold
5module regex at "trilogy:regex"
67-const init = {|
8 "red" => 0,
9 "green" => 0,
10 "blue" => 0,
···4module array at "trilogy:array" use map, flatmap, fold
5module regex at "trilogy:regex"
67+slot init = {|
8 "red" => 0,
9 "green" => 0,
10 "blue" => 0,
···5module record at "trilogy:record" use values
6module iter at "trilogy:iter" use count, filter, rangex
78-const N = -0i1
9-const S = 0i1
10-const E = 1
11-const W = -1
1213func get pos grid = with grid.(im pos).(re pos) else cancel '#'
14func adj pos = $(d + pos for d in [N, S, E, W])
···5module record at "trilogy:record" use values
6module iter at "trilogy:iter" use count, filter, rangex
78+slot N = -1i
9+slot S = 1i
10+slot E = 1
11+slot W = -1
1213func get pos grid = with grid.(im pos).(re pos) else cancel '#'
14func adj pos = $(d + pos for d in [N, S, E, W])
+4-4
2023/21/p2.tri
···5module record at "trilogy:record" use values
6module iter at "trilogy:iter" use count, filter, rangex
78-const N = -0i1
9-const S = 0i1
10-const E = 1
11-const W = -1
1213func get pos grid = with grid.(im pos).(re pos) else cancel '#'
14func adj pos = $(d + pos for d in [N, S, E, W])
···5module record at "trilogy:record" use values
6module iter at "trilogy:iter" use count, filter, rangex
78+slot N = -1i
9+slot S = 1i
10+slot E = 1
11+slot W = -1
1213func get pos grid = with grid.(im pos).(re pos) else cancel '#'
14func adj pos = $(d + pos for d in [N, S, E, W])
+1-1
2023/22/p1.tri
···7module regex at "trilogy:regex"
8module iter at "trilogy:iter" use range
910-const line_regex = regex::new "(\\d+),(\\d+),(\\d+)~(\\d+),(\\d+),(\\d+)"
11func parse str =
12 let matches = line_regex::matches str,
13 normalize (cast (matches.1):cast (matches.2):cast (matches.3)) (cast (matches.4):cast (matches.5):cast (matches.6))
···7module regex at "trilogy:regex"
8module iter at "trilogy:iter" use range
910+slot line_regex = regex::new "(\\d+),(\\d+),(\\d+)~(\\d+),(\\d+),(\\d+)"
11func parse str =
12 let matches = line_regex::matches str,
13 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
···7module regex at "trilogy:regex"
8module iter at "trilogy:iter" use range
910-const line_regex = regex::new "(\\d+),(\\d+),(\\d+)~(\\d+),(\\d+),(\\d+)"
11func parse str =
12 let matches = line_regex::matches str,
13 normalize (cast (matches.1):cast (matches.2):cast (matches.3)) (cast (matches.4):cast (matches.5):cast (matches.6))
···7module regex at "trilogy:regex"
8module iter at "trilogy:iter" use range
910+slot line_regex = regex::new "(\\d+),(\\d+),(\\d+)~(\\d+),(\\d+),(\\d+)"
11func parse str =
12 let matches = line_regex::matches str,
13 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
···5module set at "trilogy:set" use contains, length
6module tuple at "trilogy:tuple" use fst
78-const N = -0i1
9-const S = 0i1
10-const E = 1
11-const W = -1
1213func walkable ^E '>' = true
14func walkable ^W '<' = true
···5module set at "trilogy:set" use contains, length
6module tuple at "trilogy:tuple" use fst
78+slot N = -1i
9+slot S = 1i
10+slot E = 1
11+slot W = -1
1213func walkable ^E '>' = true
14func walkable ^W '<' = true
+4-4
2023/23/p2.tri
···6module record at "trilogy:record"
7module tuple at "trilogy:tuple" use fst
89-const N = -0i1
10-const S = 0i1
11-const E = 1
12-const W = -1
1314func walkable '#' = false
15func walkable _ = true
···6module record at "trilogy:record"
7module tuple at "trilogy:tuple" use fst
89+slot N = -1i
10+slot S = 1i
11+slot E = 1
12+slot W = -1
1314func walkable '#' = false
15func walkable _ = true
···6module set at "trilogy:set" use intersection, length
7module array at "trilogy:array"
89-const card_regex = regex::new "Card\\s+\\d+:([^|]+)\\|([^|]+)"
1011func parse_nums numstr = [| num::cast x for x in numstr |> split " " and is x != "" |]
12func parse_card card = parse_nums card.1 : parse_nums card.2
···6module set at "trilogy:set" use intersection, length
7module array at "trilogy:array"
89+slot card_regex = regex::new "Card\\s+\\d+:([^|]+)\\|([^|]+)"
1011func parse_nums numstr = [| num::cast x for x in numstr |> split " " and is x != "" |]
12func parse_card card = parse_nums card.1 : parse_nums card.2
+1-1
2023/4/p2.tri
···6module set at "trilogy:set" use intersection, length
7module array at "trilogy:array" use fold
89-const card_regex = regex::new "Card\\s+\\d+:([^|]+)\\|([^|]+)"
1011func parse_nums numstr = [| num::cast x for x in numstr |> split " " and is x != "" |]
12func parse_card card = parse_nums card.1 : parse_nums card.2
···6module set at "trilogy:set" use intersection, length
7module array at "trilogy:array" use fold
89+slot card_regex = regex::new "Card\\s+\\d+:([^|]+)\\|([^|]+)"
1011func parse_nums numstr = [| num::cast x for x in numstr |> split " " and is x != "" |]
12func parse_card card = parse_nums card.1 : parse_nums card.2
+1-1
2023/5/p1.tri
···6module record at "trilogy:record"
7module iter at "trilogy:iter" use collect, of
89-const heading_regex = regex::new "(\\w+)-to-(\\w+) map:"
10func parse_section [heading, ..ranges] =
11 let {| 1 => from, 2 => to, .._ |} = heading_regex::matches heading,
12 let parsed_ranges = map (str::split " " >> map cast) ranges,
···6module record at "trilogy:record"
7module iter at "trilogy:iter" use collect, of
89+slot heading_regex = regex::new "(\\w+)-to-(\\w+) map:"
10func parse_section [heading, ..ranges] =
11 let {| 1 => from, 2 => to, .._ |} = heading_regex::matches heading,
12 let parsed_ranges = map (str::split " " >> map cast) ranges,