Koru Just Solved All of Advent of Code 2015
Koru solves every part of Advent of Code 2015 — all 49 of them, since day 25 is the only single-part puzzle in the event’s history. Every solution is pure .k: no host escapes, no puzzle-specific workarounds. The whole corpus runs through run_regression.sh with leak checking enabled: 49 passed, 0 failed.
Green doesn’t mean polished, and it shouldn’t be read that way. Read the solutions and you’ll find real warts — coordinates packed into an i64 because there’s no point type, parity arithmetic selecting actors without a branch, eight parameters threaded through four recursive tors. This post is not a victory lap; it’s a receipt and a roadmap. The follow-up posts walk the tor five days at a time, read every solution, and ask whether each spelling is worth keeping — where it isn’t, we fix the language.
If you have never seen Koru, this post is the orientation.
Koru, in one page
Koru is a language built around two ideas that are usually separate: flows with named branches, and compile-time obligations.
A flow pipes a value left to right with |>, and operations answer with named outcomes instead of returning-or-throwing:
std/fs:read-lines(path: "input.txt")
! line l |> for(l)
! each c |> ...
| done _ |> _
| failed e |> std/io:print.ln("FAILED {{ e:s }}") ! arms are effects that can resume; | done and | failed are the only ways the stream ends. There is no exception hierarchy — outcomes are part of the type surface.
State that must persist across steps lives in capture cells — immutable-looking records threaded through the flow:
capture { floor: 0[i32] }
! as acc |> ...
|> captured { floor: acc.floor + 1 }
| captured result |> std/io:print.ln("{{ result.floor:d }}") Owned values carry phantom types that track custody at compile time: <heap!> issues an obligation (this must be freed), <heap> borrows it, <!heap> consumes and discharges it. The checker follows the obligation path-by-path, so a std/set created inside a loop is freed whether you meant it to be or not — leaks are type errors.
And modules can synthesize code at compile time. std/list:new(<element>) doesn’t instantiate a generic — it materializes a concrete List_i64 or List_string container into your module on first use. There is no List<T> type system; specialization is synthesis, not generics.
The corpus
Every row below is a real regression test under tests/regression/810_AOC_2015/ — an executable .k file, a real expected.txt, verified by the same harness as everything else, leak-checked. Click a check to read the test and its generated learn page.
| ✅ | 1·1 — floor counting | a scalar fold; no collection needed at all |
| ✅ | 1·2 — basement position | the same fold, asked to stop early |
| ✅ | 2·1 — wrapping paper | arithmetic over parsed dimension triples |
| ✅ | 2·2 — ribbon | same parse, different metric |
| ✅ | 3·1 — visited houses | set membership: "visited at least once" |
| ✅ | 3·2 — two Santas | two actors sharing one visited set, alternating |
| ✅ | 4·1 — MD5 prefix hunt | crypto primitive + search-until-predicate |
| ✅ | 4·2 — six zeros | the same search, a harder predicate |
| ✅ | 5·1 — nice strings | char-level pair/triple predicates |
| ✅ | 5·2 — nicer strings | string-map borrows across user-tor params |
| ✅ | 6·1 — light grid | instruction simulation over `std/grid` |
| ✅ | 6·2 — brightness | same grid, different accumulator |
| ✅ | 7·1 — wire circuit | fixpoint resolution over a rule table |
| ✅ | 7·2 — override wire b | a user tor owning a map lifecycle, run twice |
| ✅ | 8·1 — escape codes | char-level state machine over string data |
| ✅ | 8·2 — re-encode length | encode/decode round-trip |
| ✅ | 9·1 — shortest route | permutation search over city distances |
| ✅ | 9·2 — longest route | the same search, inverted objective |
| ✅ | 10·1 — look-and-say | the sequence as a packed-i64 number |
| ✅ | 10·2 — six rounds | same encoding, one more round |
| ✅ | 11·1 — next password | validity as arithmetic over base-26 digits |
| ✅ | 11·2 — second password | the same search, iterated once more |
| ✅ | 12·1 — JSON numbers | a scanner that skips strings |
| ✅ | 12·2 — ignore objects | depth-tracking parse |
| ✅ | 13·1 — seating chart | circular permutation optimization |
| ✅ | 13·2 — seat yourself | the same optimizer, new constraint |
| ✅ | 14·1 — reindeer race | per-second state update over a roster |
| ✅ | 14·2 — points race | leader-change detection every tick |
| ✅ | 15·1 — cookie scoring | nested-loop search over ingredient space |
| ✅ | 15·2 — 500 calories | the same search, plus a filter |
| ✅ | 16·1 — Sue matching | multi-field record comparison |
| ✅ | 16·2 — ranged matching | inequality predicates over the same records |
| ✅ | 17·1 — container subsets | combinatorial enumeration, count the hits |
| ✅ | 17·2 — minimum containers | same enumeration, different objective |
| ✅ | 18·1 — Game of Life | grid cellular automaton |
| ✅ | 18·2 — stuck corners | same automaton, pinned cells |
| ✅ | 19·1 — one replacement | string rewriting + dedup set |
| ✅ | 19·2 — fabricate it | IDDFS over rewrite rules — recursion with borrowed collections |
| ✅ | 20·1 — house numbers | divisor-sum number theory |
| ✅ | 20·2 — lazy elves | the same theory, skipping non-divisors |
| ✅ | 21·1 — cheapest win | shop loadout vs boss stats |
| ✅ | 21·2 — priciest loss | the same comparison, inverted |
| ✅ | 22·1 — scripted fights | turn-based state machine replay |
| ✅ | 22·2 — least mana | Dijkstra over packed states — needed `std/heap` |
| ✅ | 23·1 — register machine | parse a program, interpret it |
| ✅ | 23·2 — a=1 | the same machine, the real 47-instruction input |
| ✅ | 24·1 — 3-way balance | subset-sum partitioning |
| ✅ | 24·2 — 4-way balance | same partition, deeper search |
| ✅ | 25·1 — diagonal table | closed-form indexing + modular exponentiation — no iteration at all |
What the solutions demonstrate
Four pieces of the corpus are worth reading closely, because each one exercises a different part of the language under real load.
Named groups are the destructure (day 2). std/regex:match returns capture groups as a branch payload schema — the pattern is the contract:
| `(?<l>[0-9]+)x(?<w>[0-9]+)x(?<h>[0-9]+)` { l: i64, w: i64, h: i64 } |> ... The i64 types convert text to int at the splice; a non-matching line is a named | no-match arm. No unwrap, no error path — the regex either matches the schema or it doesn’t.
Unbounded search is a label fold (day 4). #search/@search threads a candidate through miss/found payloads with no mutation:
mine = #search std/crypto:md5-check(key, n: 1, zeros)
| miss v |> @search(key, n: v, zeros)
| found r -> r The search protocol is named — miss keeps going, found delivers — rather than hidden inside a predicate.
Collections obey the phantom protocol under recursion (days 7, 19, 22). A user tor can take *List_i64<list> or *Map_i64_i64<map> as a borrow parameter and recurse through it — the obligation stays with the caller, the callee reads and writes in place, and free discharges at the boundary. Day 19 part 2 is a recursive IDDFS over rewrite rules doing exactly this; day 22 part 2 is Dijkstra over packed combat states doing it while a std/heap priority queue drains the frontier.
std/heap exists because the corpus needed it (day 22 part 2). Optimal play is uniform-cost search: states pack into i64 (spent << 47 | state), the heap key packs cost and state into one i64 so plain integer order is the search order, and std/map holds distances with lazy stale-entry deletion. The heap is a binary min-heap over i64 keys with the same <heap>/<heap!>/<!heap> protocol as every other collection — born from the puzzle, shipped as stdlib.
Boundaries
Two tests pin the statement’s numbers rather than the real puzzle input, and their headers say why: day 10’s real input runs 50 look-and-say rounds producing a ~20-million-digit sequence — a different surface entirely, documented in 810_101’s header and inherited by 810_102. Day 25 is single-part by the tor’s own design. Everything else runs the real input.
The series
Five posts follow, one per five-day group, each a design review of the actual solutions: days 1–5 (strings and grids), 6–10 (state and wires), 11–15 (search), 16–20 (simulation), 21–25 (machines). The question each post asks is the same — is every spelling worth keeping? — and the answer is allowed to be “fix the language.”