The Iron Mines
In which our protagonist discovers that the kingdom's economy is a system too, and it is broken.
The mine foreman came to the guild hall at dawn and said: "We are four days from closing, and when we close, three hundred miners lose their jobs and the town loses a quarter of its tax revenue, and I have heard you fixed the water, and I am told you think in systems, and I am here to ask if you can save us."
Her name was Sera. She was grizzled, square-shouldered, and had the specific calm of a person who had been mining since she was twelve and had stopped being impressed by anything short of a tunnel collapse. She was not, in the dry language of the system in his head, asking for a miracle. She was asking for a refactor.
[detect_mana: 1 source. Threat level: none. Stamina: 92%.]
[Compiler note: this is a person who has been underground too long and is, in a small way, immune to small talk.]
"Sit," Kenji said, and pulled up a chair.
Sera sat. She did not waste time. She laid the problem out in the same way she would have laid out a vein map: clean, specific, with the rough patches marked.
The iron veins were running diagonally through hard rock. The miners had been following them in long winding tunnels that were getting deeper and more dangerous with every foot. The cost of supporting the tunnels, hauling the ore out, and keeping the workers safe was eating all the profit. The mine owner, a portly man named Harren, had been bleeding money for two years, and the mayor, who had been watching the bleed, had finally decided to call in the strange foreigner.
"I can look," Kenji said. "I cannot promise to fix it."
"You can look. That is more than anyone else has offered."
They went to the mines. Kenji walked the tunnels for an entire day. He did not cast spells. He did not give orders. He looked. He asked questions. He climbed down ladders and crawled through narrow passages and talked to the miners, who were a taciturn and practical bunch, and who, by the end of the day, had decided that this strange foreigner was at least not an idiot.
[detect_ore: 47 veins mapped. Density: low (avg 0.3). Trend: thinning with depth.]
[Compiler note: the developer is following the wrong variable. The system is, in a small way, ahead of him.]
The system had, in a small way, given him a hint. The system was, in the driest possible language, telling him to look at the data, not the path.
That night, he sat in his room at the guild hall, with Pip orbiting his head and Lian sitting across from him with her notebook open, and he drew a diagram.
"The problem is not that the veins are thin," he said. "The problem is that we are following them. We are paying for the path, not the ore. We are optimizing for the wrong variable."
"What is the right variable?" Lian asked.
"The vein density. We need to find the densest ore first, extract it in straight lines, and only follow the thinner veins if the straight extraction leaves time."
"Straight lines are faster."
"Straight lines are also cheaper. We do not need to support the tunnels as much. We do not need to haul as far. We do not need to send miners down narrow passages where they can barely fit. We can use larger equipment. We can use more workers per tunnel. We can do, in short, an extraction algorithm."
He pulled out a piece of paper and started writing pseudocode. It was not a real spell. It was an algorithm for choosing which tunnels to dig first, based on vein density, depth, and proximity to the surface. It was, in the driest possible language, a planner.
Lian watched, fascinated. "That is a math spell."
"It is a planning spell. We define the inputs. The Compiler generates the actual mining plan. The miners follow the plan. We save money."
"Will it work?"
"I think so. Let me test it."
He spent the next two days refining the algorithm with Sera, who understood the rock better than anyone, and Lian, who understood the math better than him, and Harren, who understood the money better than either of them. By the end of day three, they had a new mining plan, focused on the three densest veins, with straight tunnels and a centralized haulage system.
[extraction_plan: 3 primary veins, 7 secondary veins, 2 haulage levels]
[Compiler note: this plan will recover 14% more ore in 60% of the time. The system approves.]
[Compiler note: the developer is, in a small way, learning to write planners.]
The first new tunnel was dug in four days. The previous tunnels had taken three weeks for less ore. By the end of the month, the mines were profitable again. Harren, who had come to Kenji as a skeptic, sent him a small purse of gold and a hand-written note that said: "You saved three hundred jobs. The town is in your debt."
Kenji gave the purse to Lian. "Your apprenticeship fee. Spend it on books."
Lian's eyes went wide. "That is too much."
"It is exactly enough. Now go buy books."
She went. Kenji watched her leave, and Pip pulsed, amused. The pulse felt like: "Soft."
Kenji sent back: "Yeah. A little."
But the algorithm was not soft. The algorithm was the kind of thing that scaled. The principle of finding the densest vein first and extracting in straight lines was the same principle that would, in two years, run the resource allocation for a much larger territory, in a much harder crisis, when the audit magic of a king's court would have to decide which towns got food and which towns did not, and the wrong answer would have meant people dying in the snow.
He did not know that yet. He knew only that the mine was profitable, the miners had their jobs, and the algorithm was the first thing he had built in this world that was, in any meaningful sense, infrastructure.
Pip pulsed again. The pulse felt like: "Famous."
Kenji sent back: "Not yet. But maybe soon."
[Compiler note: reputation spreading. Regional reports indicate 3 inquiries from neighboring towns in the last 7 days.]
[Compiler note: the developer is, in a small way, becoming a name.]
The system was, in a small way, ahead of him. The system was, in the driest possible language, telling him what he could not yet see: the algorithm he had written in a room above a tavern was the kind of thing that kings, in a year and a half, would be willing to pay a great deal to learn.
He went to bed that night with the smell of the mine still on his hands, and Pip on his shoulder, and the soft hum of the aquifer in the walls, and he thought about the through-line. Any sufficiently well-defined problem is solvable.
The next problem, he was beginning to realize, would not be a local one. The next problem would be a regional one. And after that, a kingdom one. And after that, he did not yet know.
But the algorithm was the same. The algorithm was always the same. Find the densest vein. Drill in straight lines. Save the people who needed saving. The variables would change. The principle would not.
Pip pulsed, soft, in a tone that was, in a small way, ahead of him, and the pulse felt like: "Get some sleep. You have a date with the captain of the guard at midnight, and you are going to need to be awake for it."
Kenji sent back, surprised: "How do you know about that?"
Pip pulsed again. The pulse felt like: "I notice things. I am, in a small way, a colleague."