Part 12 of 39
The Endless Loop
By Madhav Kaushish · Ages 10+
Glagalbagal's morning counting tablet worked. Krothva could count animals out of the enclosure without supervision. But the evening procedure — counting animals back in — was a different matter.
The Evening Tablet
The evening procedure was the reverse of the morning one. In the morning, each animal exiting caused a pebble to be added. In the evening, each animal entering caused a pebble to be removed. If the baskets were empty at the end, all animals had returned.
Glagalbagal carved the evening tablet:
Step 1. Wait for an animal to enter the enclosure. Step 2. When an animal enters, remove one pebble from basket 1. Step 2a. If basket 1 is empty and you need to remove a pebble, take one pebble from basket 2 and place five pebbles in basket 1, then remove one. Step 2b. If basket 2 is also empty, take one pebble from basket 3 and place four pebbles in basket 2, then proceed with Step 2a. Step 3. Continue until no more animals are entering the enclosure.
The borrowing rules (Steps 2a and 2b) were correct — he had learned those from the tax calculation. And the stopping condition in Step 3 seemed natural: when no more animals are coming in, you are done.
He assigned the evening count to Krothva and went to bed.
Vrjsk
He was woken before dawn by Blortz.
Blortz: Krothva is still counting.
Glagalbagal walked to the enclosure. Krothva was standing at her post, visibly exhausted, mechanically removing pebbles from the baskets. The baskets showed a count far below zero — she had borrowed so many times that the arrangement made no physical sense.
The problem was a goat named Vrjsk. Vrjsk had discovered a gap in the fence, and throughout the night had been slipping out of the enclosure, wandering to a nearby bush, eating for a few minutes, and wandering back in. Every time Vrjsk re-entered, Krothva observed an animal entering and dutifully removed a pebble. Vrjsk had gone in and out dozens of times. Krothva had removed dozens of pebbles for a single goat.
And she had never stopped, because the instruction said "continue until no more animals are entering" — and there was always one more animal entering. Vrjsk kept coming back.

The Bad Stopping Condition
Glagalbagal's error was in Step 3. "Continue until no more animals are entering" depended on the behaviour of the animals. If the animals cooperated — entered once and stayed — the condition would eventually be met. But Vrjsk did not cooperate, and the instruction had no way to handle that.
The deeper issue was that the stopping condition was not something Krothva could ever be certain about. Even without Vrjsk, how long should Krothva wait before deciding that no more animals were entering? Five minutes? An hour? An animal might be slow. The condition "no more animals are entering" required Krothva to predict the future, which she could not do.
The Fix
Glagalbagal needed a stopping condition based on something fixed and known — not on the unpredictable behaviour of goats.
He revised the tablet:
Step 3. After removing a pebble, check whether all baskets are empty. If all baskets are empty, stop — all animals have returned.
This was better. The morning count had placed a fixed number of pebbles in the baskets. The evening count removed one per animal. When the baskets were empty, the counts matched — exactly as many animals had returned as had left. Whether Vrjsk entered once or fifty times, the baskets would reach empty after the correct number of distinct entries. (The repeated entries by Vrjsk would push the count below zero, which would still indicate a problem — but more on that later.)
Actually, the Vrjsk problem was subtler. Krothva had no way to tell if an entering animal had already been counted. The revised stopping condition would cause her to finish too early — she would reach empty baskets after, say, a hundred and seventy entries, but if Vrjsk accounted for thirty of those, only a hundred and forty distinct animals had returned. Ten were still missing, and the baskets said everything was fine.
Glagalbagal realised the stopping condition alone was not enough. He also needed to fix the fence.
The Safety Limit
While the fence was being repaired (a job assigned to a triceratops, since velociraptors lacked the temperament for construction work), Glagalbagal added one more line to the evening tablet:
Step 4. If you have removed more pebbles than twice the morning count, stop immediately and report an error to Blortz.
This did not solve the Vrjsk problem. But it prevented the worst outcome — Krothva counting all night until the baskets reached some absurd negative state. If the procedure was going wrong, it would at least stop going wrong within a bounded amount of time.