{ 1998–2001 }
A maze, a car park and a frog: how I got to recursion
In 9th grade I badly wanted to go to the informatics olympiad, but they wouldn’t even send me to the district round. Our school was a strong one, the district olympiad was held right in it, and there was no school round: the informatics teacher simply named who would go. To me he said: “You’re still too young.” Even though you could take part from 8th grade, and the younger ones even had a division of their own.
The computer room back then was run by older students, two or three years above me: strong guys, practically with computer clubs of their own. Once the teacher stepped out and left one of them in charge. I asked if I could sit in. “Close the door,” he said. I closed it. “No, from the other side.” I was a real stay-at-home kid and didn’t get jokes like that. But the same guys showed me a trick: put a dot, a forbidden character, into a folder’s name with a disk editor, and nobody can get into that folder any more.
When I went into 10th grade, they had finished school, and the teacher said: “All right, go then.” At the district olympiad I got a maze, a tiny one, 3×3 or 4×4, that had to be walked through. I got stuck. I wrote loops inside loops, this way and that, but I didn’t know recursion yet, and without it the problem wouldn’t give.
Even earlier, before 10th grade, I had read a puzzle in the magazine Nauka i Zhizn (“Science and Life”) about parking outside a restaurant. If cars park along the markings, more of them fit than if each one stops wherever it likes. The question was how many cars fit on average in the second case. Back then I didn’t even understand how you could calculate such a thing. A year or two later I remembered it and saw: this is recursion. A car stops at a random spot, the free stretch splits in two, and the same thing happens in each part. Call that function a thousand times and take the average. Later I learned it is the well-known Rényi parking problem.
In 11th grade I solved all three problems at the district olympiad for full marks. One was about a frog that jumps two or three squares: in how many ways can it get to the end? That is pure dynamic programming, exactly what we had studied at the Progmeistars courses. When I heard the results, it was probably the happiest moment of that time: I ran half the way home, I had so much energy.
That is how I got to the national olympiad for the first time. It was held in a computer room at the University of Latvia, where I later studied. I solved almost nothing. Next to me sat practically a grown man, a big guy who already had a moustache coming in, and I thought: “A schoolboy? That’s not fair.” He turned out to be my age, also in 11th grade: Alexander Belov. Later we went to olympiads together, became friends and studied at university together.
A year later came the bracket problem and the IOI gold.
What I took from it: some problems don’t give in to persistence: you need a tool you don’t have yet. But once you have it, old puzzles you couldn’t crack suddenly fall into place by themselves.