···11import "trilogy:debug" use dbg
22import "trilogy:io" use readlines
33import "trilogy:string" use chars, chomp
44-import "trilogy:number" use from_digit, max
44+import "trilogy:number" use from_digit
55+import "trilogy:compare" use max
56import "trilogy:iterator" as it
67import "trilogy:array" as arr use take, skip
78
+2-2
2025/5/p2.tri
···33import "trilogy:array" use sort_by, fold
44import "trilogy:parsec" use parse, apply, integer, char, per_line
55import "trilogy:iterator" as it
66-import "trilogy:number" use max
66+import "trilogy:compare" use max, asc
7788proc input!() {
99 let range = do() {
···1818proc main!() {
1919 let fresh:_ = readall!()
2020 |> parse input
2121- |> sort_by (fn a b. a.'left < b.'left)
2121+ |> sort_by (asc <| fn a. a.'left)
2222 |> fold (fn (fresh:index) (low:high). fresh + ((max index (high + 1)) - (max index low)):(max index (high + 1))) (0:0)
2323 dbg!(fresh)
2424}
+2-1
2025/7/p1.tri
···11import "trilogy:debug" use dbg
22import "trilogy:io" use readlines
33import "trilogy:string" use split, chomp
44-import "trilogy:number" use max, im
44+import "trilogy:compare" use max
55+import "trilogy:number" use im
56import "trilogy:array" use map, reduce, length
67import "trilogy:set" use push, contains, collect
78import "trilogy:iterator" as it
+2-1
2025/7/p2.tri
···11import "trilogy:debug" use dbg
22import "trilogy:io" use readlines
33import "trilogy:string" use split, chomp
44-import "trilogy:number" use max, im
44+import "trilogy:number" use im
55+import "trilogy:compare" use max
56import "trilogy:array" use map, reduce, length
67import "trilogy:set" use push, contains, collect
78import "trilogy:iterator" as it
+2-2
2025/8/p1.tri
···44import "trilogy:array" use push, collect, sort_by, take, reduce
55import "trilogy:core" use length
66import "trilogy:iterator" as it
77+import "trilogy:compare" use asc
78import "trilogy:set" use union
89910func dist [x1, y1, z1]:[x2, y2, z2] = (x1-x2)**2 + (y1-y2)**2 + (z1-z2)**2
1010-func dist_asc a b = dist a < dist b
11111212proc main!() {
1313 let points = readlines
···2525 i += 1
2626 }
2727 dbg!(length edges)
2828- edges sort_by= dist_asc
2828+ edges sort_by= (asc dist)
2929 dbg!("sorted")
3030 edges take= 1000
3131 dbg!("taken")
+27
2025/9/p1.tri
···11+import "trilogy:io" use readlines
22+import "trilogy:debug" use dbg
33+import "trilogy:parsec" use parse, sep_by, char, integer
44+import "trilogy:array" use collect, length
55+import "trilogy:number" use abs
66+import "trilogy:compare" use max
77+import "trilogy:iterator" use map
88+99+func area [x1, y1] [x2, y2] = (abs (x1 - x2) + 1) * (abs (y1 - y2) + 1)
1010+1111+proc main!() {
1212+ let points = readlines
1313+ |> map (parse (sep_by (char ',') integer))
1414+ |> collect
1515+1616+ let mut best = 0
1717+ let mut i = 0
1818+ while i < length points {
1919+ let mut j = i + 1
2020+ while j < length points {
2121+ best max= (area (points.i) (points.j))
2222+ j += 1
2323+ }
2424+ i += 1
2525+ }
2626+ dbg!(best)
2727+}
+110
2025/9/p2.tri
···11+import "trilogy:io" use readlines
22+import "trilogy:debug" use dbg
33+import "trilogy:parsec" use parse, sep_by, char, integer
44+import "trilogy:array" use collect, length, map, reduce, first, tail, filter, sort, sort_by, any, push, zip
55+import "trilogy:number" use abs
66+import "trilogy:compare" use max, asc
77+import "trilogy:iterator" as it
88+99+func area [x1, y1] [x2, y2] = (abs (x1 - x2) + 1) * (abs (y1 - y2) + 1)
1010+1111+func is_horizontal [_, y1]:[_, y2] = y1 == y2
1212+func is_vertical [x1, _]:[x2, _] = x1 == x2
1313+1414+func collide p1:p2 [bx1, by1]:[bx2, by2] =
1515+ let [px1, px2] = sort [x p1, x p2],
1616+ let [py1, py2] = sort [y p1, y p2],
1717+ px1 < bx2
1818+ && px2 > bx1
1919+ && py1 < by2
2020+ && py2 > by1
2121+2222+func x [a, _] = a
2323+func y [_, a] = a
2424+2525+func left a:_ = a
2626+2727+func contains_by key (a:b) (p1:p2) =
2828+ let [w, z] = sort [key p1, key p2],
2929+ w <= a && a <= z && w <= b && b <= z
3030+3131+proc main!() {
3232+ let points = readlines
3333+ |> it::map (parse (sep_by (char ',') integer))
3434+ |> collect
3535+ dbg!('points(length points))
3636+3737+ let edges = zip points [..tail points, first points]
3838+ dbg!('edges(length edges))
3939+4040+ # It has been observed that the shape is convex and without holes or interior crossings
4141+ #
4242+ # So we can make a series of rectangles that represent the illegal area by sending beams
4343+ # from each edge
4444+ let verticals = sort_by (asc <| (x << left)) <| filter is_vertical edges
4545+ dbg!('verticals(length verticals))
4646+4747+ let horizontals = sort_by (asc <| (y << left)) <| filter is_horizontal edges
4848+ dbg!('horizontals(length horizontals))
4949+5050+ let xs = map (x << left) verticals
5151+ dbg!('xs(length xs))
5252+5353+ let ys = map (y << left) horizontals
5454+ dbg!('ys(length ys))
5555+5656+ let [min_x, .._, max_x] = xs
5757+ let [min_y, .._, max_y] = ys
5858+5959+ let illegal = []
6060+6161+ dbg!(min_x:max_x)
6262+ dbg!(min_y:max_y)
6363+6464+ let x_ranges = zip xs (tail xs)
6565+ let mut i = 0
6666+ while i < length x_ranges {
6767+ let x1:x2 and range = x_ranges.i
6868+ i += 1
6969+ if x1 == x2 { continue unit }
7070+ let [y1, .._, y2] = horizontals
7171+ |> filter (contains_by x range)
7272+ |> map (y << left)
7373+ |> sort
7474+ push!(illegal, [x1, min_y]:[x2, y1])
7575+ push!(illegal, [x1, y2]:[x2, max_y])
7676+ }
7777+ dbg!('illegal(length illegal))
7878+7979+ let y_ranges = zip ys (tail ys)
8080+ let mut i = 0
8181+ while i < length y_ranges {
8282+ let y1:y2 and range = y_ranges.i
8383+ i += 1
8484+ if y1 == y2 { continue unit }
8585+ let [x1, .._, x2] = verticals
8686+ |> filter (contains_by y range)
8787+ |> map (x << left)
8888+ |> sort
8989+ push!(illegal, [min_x, y1]:[x1, y2])
9090+ push!(illegal, [x2, y1]:[max_x, y2])
9191+ }
9292+ dbg!('illegal(length illegal))
9393+9494+ # Then we just run standard collision of the area boxes with those
9595+ let mut best = 0
9696+ let mut i = 0
9797+ while i < length points {
9898+ let mut j = i + 1
9999+ while j < length points {
100100+ let a = points.i
101101+ let b = points.j
102102+ if !(any (collide (a:b)) illegal) {
103103+ best max= (area a b)
104104+ }
105105+ j += 1
106106+ }
107107+ i += 1
108108+ }
109109+ dbg!(best)
110110+}