2026-12-01: Dusty Shed
Advent of Code 2026, Day 1 in Sabre
Today's challenge started with determing the three most common identifiers in a given list, then multiplying them together. The second part of the solution then swapped the selection of identifiers with the three least common ones.
Solution Steps
The first part of my solution involed parsing an input file of line-delimited 3-digit numbers. Immediately I went to reach for a split or explode string utility, but realized that I had not yet implemented these for String values. Since every line of the input file was exactly 3-bytes for the numeric and 1-byte for the delimiter, I decided to use the Buffer.fold utility to manually convert bytes into our numerics required:
//! @brief Reads the input as an array of identifiers.
//! @param fp Input file-path.
let read_input = fn (fp: String): List[Number] {
mut index = -1; // index record
let buffer = FS.read_file(fp);
// read the input list of numbers available
return buffer.fold([], fn (acc: List, byte: Number): List {
// update the current index value now
index += 1;
// get the current digit to be added
let digit = byte - 48;
// check what we should do with the current index
match (index % 4) {
0: acc.push_back(digit),
1: acc.set(-1, (acc.back() * 10) + digit),
2: acc.set(-1, (acc.back() * 10) + digit),
}
// and return the resulting accumulator now
return acc;
});
};Afterwards, to get the solution sets I needed a way to count the frequency of each numeric that we parsed. Initially I went to again grab something that Sabre does not yet have, which was to use an associative object for holding counts of numerics. So instead since the numerics were ranged from 100 to 999, I created a frequency array with a maximum size of 1000 to hold each numerics count. From here, I could simply increment the count of each identifier as I found them:
let counts = List.filled(1000, 0);
let identifiers = read_input("data/input");
for (nn in identifiers) counts.set(nn, counts.get(nn) + 1);Sorting the maximum and minimum counts also proved to be troublesome (again!), since I had not yet implemented any sorting utilities for List values. This meant that I had to keep track of a queue of extremities rather crudely:
// The extremities that we are searching for
let maximums = [[0, -1], [0, -1], [0, -1]];
let minimums = [[0, oob], [0, oob], [0, oob]];
// If we iterate over the available counts:
for (count, ii in counts) {
// Ignore all empty counts (unseen numerics)
if (count == 0) continue;
// Crudely record any incoming minimum counts
if (count < minimums.get(0).get(1)) {
minimums.set(2, minimums.get(1));
minimums.set(1, minimums.get(0));
minimums.set(0, [ii, count]);
} else if (count < minimums.get(1).get(1)) {
minimums.set(2, minimums.get(1));
minimums.set(1, [ii, count]);
} else if (count < minimums.get(2).get(1)) {
minimums.set(2, [ii, count]);
}
// Crudely record any incoming maximum counts
if (count > maximums.get(0).get(1)) {
maximums.set(2, maximums.get(1));
maximums.set(1, maximums.get(0));
maximums.set(0, [ii, count]);
} else if (count > maximums.get(1).get(1)) {
maximums.set(2, maximums.get(1));
maximums.set(1, [ii, count]);
} else if (count > maximums.get(2).get(1)) {
maximums.set(2, [ii, count]);
}
}From here I could simply use the List.fold utility again to multiply each of the desired extremities together for each of the solutions.
Looking Ahead
Although I was able to get a solution today without modifying Sabre, I realized that I am missing a few tools that will greatly help me with future solutions. To simplify this process, I will be publishing a v0.5.0-canary rolling release of Sabre during this challenge. Additionally, I plan to introduce a engine manifest field to restrict usage of incompatible versions of Sabre with a project. This will also make clear that in future some of these solutions may become outdated to certain versions ongoing of Sabre.
For now I plan to implement a few of the missing utilities I noted during today's challenge, plus maybe a couple extra to prepare for anything that may catch me out or to simplify parts of this challenge (eg: resolving paths relative to a script). Until tomorrow!