29. Advent of Logic Mill
Snow had come early to Dorpat that year, settling thin and hesitant on the roofs, as if unsure whether it truly belonged. Mihkel was alone in the workshop, oiling a stubborn cog of the Logic Mill, when a sound cut through the quiet: three careful knocks, too light for a man’s fist, too deliberate for the wind.
He hesitated. Few knew of this place, and fewer still had reason to visit it after dusk. When he opened the door, lamplight fell upon a figure no higher than his waist, wrapped in a woollen cloak dusted with frost. The face beneath the hood was sharp, old in a way that had nothing to do with years, and alert with practised precision.
„Good evening,“ the stranger said, bowing with unexpected formality. „You are Mihkel of Dorpat. The one who solves troublesome reckonings.“
Mihkel felt a brief, unworthy surge of pride before reason reasserted itself. Folklore had trained him to expect horns, bells, or at least a whiff of sulphur. This creature smelled only of cold air and pine resin. „You have the advantage of me,“ Mihkel replied.
„I am called many things,“ said the visitor. „Elf will suffice.“
Over a mug of weak tea, the elf spoke of the North Pole: a place of ice and wind, chosen not for secrecy alone, but for distance. Too far, he explained with a thin, practical smile, for disappointed children to march upon in anger when gifts failed to arrive. Saint Nicholas presided over the enterprise, more administrator than saint these days, while the elves laboured by hand, as they always had.
But distance did not solve everything. Each year brought more children, more expectations, and more variations of toys assembled from ever smaller parts. What had once fit comfortably in memory now overflowed ledgers and patience alike.
„We still build everything by hand,“ the elf said, tapping the table with a gloved finger. „Part by part. Rule by rule. We know how each toy is made, but we lose track of where it truly begins.“
Mihkel listened, hearing beneath the fairy-tale cadence a familiar complaint: the tyranny of scale. He had heard it from farmers calculating yields, from clerks drowning in columns of figures. The difficulty was never the calculation itself, but the lack of a method that endured.
The elf described toys composed not of whimsy, but of substitutions: one part replaced by another, and another still, until at last one reached wood, metal, or paper. What should have been a simple tracing had become a tangle repeated millions of times.
Mihkel felt a quiet exhilaration. This was not magic, but bookkeeping under a different name. A process guaranteed to end, provided one followed it faithfully. Or built a machine that never grew tired.
His eyes drifted, unbidden, toward the shrouded bulk of the Logic Mill. He asked no questions about how the elf had found him. Instead, he asked the only safe one. „What is it you wish to know?“
The elf met his gaze. „For every toy,“ he said, „we must know what it is truly made of.“
Mihkel nodded. „Yes,“ he said. „This can be done.“
The elf smiled, grateful and exhausted all at once. Outside, the snow thickened, and for a moment the workshop seemed to stand at the edge of a much larger system, stretching far beyond Dorpat and into the polar night.
If you’re a new player, I suggest checking the tutorial first to get accustomed to how the game and the Logic Mill work.
On the input tape, you’ll get a toy’s description and its production rules. A toy is defined as a sequence of toy parts. Each toy part expands to exactly one other toy part (lowercase letter) or to a raw material (uppercase letter). Your task is to determine which final raw materials the toy consists of.
The input tape consists of two sections separated by @:
-
Toy’s description — a string of lowercase letters (
a–j) describing the toy parts. -
Production rules — a comma-separated list of rules in the form
a:b, meaning that toy partais made ofb. The right-hand sidebis either another toy part (lowercase letter) or a raw material (uppercase letter).
Raw materials are represented by uppercase letters:
W (wood),
M (metal),
P (paper).
Raw materials are final and cannot be expanded further.
To determine the final materials, process each character in the toy’s description string independently. Repeatedly apply the production rules until the character becomes a raw material. The length of the final raw materials string is always the same as the length of the toy’s description string.
The rules are guaranteed to terminate:
there are no cycles, and every toy part eventually resolves to some raw material (W, M, or P).
For example, if the input tape is a@a:c,c:W,
the output tape should be W
(a → c → W).
Another example:
afg@a:W,f:a,g:M produces WWM
(a → W, f → a → W, g → M).