20. Sudoku: Solver (Part II.)
A soft snow had settled over Dorpat that evening, swallowing the streets in silence. The lamps along the river burned dim behind their frosted glass, and in the narrow lane by the university wall, only one window glowed—Mihkel’s workshop.
Inside, the air smelled of metal shavings and candle smoke. The Logic Mill rested beneath a draped cloth, its form barely visible— a sleeping thought, hidden from the world. Mihkel sat at his desk, surrounded by papers covered in grids and half-filled numbers. He had not noticed how late it had grown until a knock startled him from his notes.
It was Liina.
Her cheeks were flushed from the cold, her eyes bright with unease. „I shouldn’t be here,“ she said softly, closing the door behind her. „They’ve begun asking questions at the press. About me. About what I write.“
Mihkel stood, unsure whether to offer comfort or caution. „Your poems?“
She nodded. „They call them dangerous. I call them true.“ Her voice trembled—not from fear, but from exhaustion. „I thought perhaps you’d understand. You, too, hide your truths behind numbers and symbols.“
The words struck something deep. For a moment, Mihkel hesitated. Then he stepped to the workbench and pulled aside the cloth.
Brass gears caught the candlelight like quiet stars. The Mill stood revealed at last.
„This is what I’ve hidden,“ he said. „They would not understand it either. They would call it unnatural, or unholy, or worse—useful to those who should never wield it.“
Liina approached slowly, as though nearing a relic. „It’s beautiful,“ she murmured. „What does it do?“
Mihkel smiled faintly, a touch of weariness in it. „It listens to order. And it restores it, when given chaos.“ He unrolled a strip of tape: a tape half-filled, half-empty—numbers like islands in snow.
„Watch,“ he said.
The gears stirred with a low hum. The tape began to creep forward under the thin steel head. Soft clicks filled the room—the rhythm of logic itself. Slowly, cell by cell, the blanks yielded to meaning. The pattern emerged: symmetry, completion, harmony reborn from absence.
Liina stood motionless, her breath caught somewhere between wonder and sorrow. „It solves puzzles the way I mend verses,“ she whispered. „One word follows another until the world makes sense again.“
Mihkel nodded. „Yes. But it cannot choose what to solve. It only obeys its laws.“
„Perhaps beauty is obedience to truth,“ she said quietly. „Even when the world fears it.“
On the input tape, you’ll get a 9×9 Sudoku board in a single line, with rows separated by = and groups of 3 cells in a row separated by |.
Empty cells are represented by 0.
Your task is to solve the Sudoku board (i.e., fill in all empty cells) and output it in the same format. Each input board has exactly one solution. The board should be solved according to the Sudoku rules: Each number from 1 to 9 can appear at most once in
- each row
- each column
- each of the nine 3×3 boxes of the grid
For example, if the input tape is
000|000|000= 000|314|579= 000|289|346= 026|493|851= 015|862|497= 094|571|263= 057|136|982= 068|925|734= 039|748|615
your output tape should be
943|657|128= 682|314|579= 571|289|346= 726|493|851= 315|862|497= 894|571|263= 457|136|982= 168|925|734= 239|748|615
(for the sake of readability, I added new lines to the example; the actual tapes don't have them)