The Curious Case of the Recursive H
Situation
Leo had already figured out how to draw a recursive H.
The idea seemed simple: draw one large H, then attach smaller H's to its corners. Each smaller H follows the same rule, becoming smaller and smaller until it reaches a stopping size.
But making the turtle perform this seemingly simple construction was another story!
Leo's first program was full of forward movements, turns, and recursive calls. The turtle had to travel around the drawing while Leo kept track of its position and direction.
He worked quietly. Not a single word. Just the turtle, the code, and a lot of concentration. LOL.
Turning Point
After some experimenting, Leo managed to produce the drawing.
But Donald noticed something inconsistent: some recursive H's seemed to have an empty corner in a different position from others.
So Leo went back to investigate.
The class even ran five minutes overtime. He eventually corrected the construction.
Then Donald offered a different perspective:
"Recursively, this is a simple job. First draw a big H, then go to three corners and draw smaller ones. That's it and that's all. The details belong to recursion."
That short explanation helped Leo reorganize his thinking. His next version of the code made the three recursive calls much easier to recognize.
Emergence
Donald then discovered something interesting: Leo had never used goto()!
Could he draw the same recursive structure by specifying coordinates instead of navigating with turtle movements?
Leo began adding x and y parameters to his recursive function.
After a while, even Donald realized that the function really did need to know its own location.
The new function became:
def drawH(n, x, y):
if n <= 10:
return
pu()
goto(x, y)
pd()
goto(x - n, y)
pu(); goto(x - n, y + n); pd()
goto(x - n, y - n)
pu(); goto(x + n, y + n); pd()
goto(x + n, y - n)
pu(); goto(x + n, y); pd()
goto(x, y)
drawH(1/2*n, x + n, y + n)
drawH(1/2*n, x + n, y - n)
drawH(1/2*n, x - n, y - n)
Now the function had three explicit pieces of information:
n: the size of the H.
x: its horizontal position.
y: its vertical position.
Instead of remembering where the turtle had travelled and which direction it was facing, Leo could tell each recursive call exactly where its smaller H belonged.
A different representation. A much clearer geometric description.
Learning
This little H adventure revealed several important ideas:
Recursion is about describing a repeated structure, not repeating a long sequence of instructions.
A good function should make the structure of the problem visible.
Position and size can be explicit parameters rather than hidden state.
The same geometric construction can be expressed through movement or coordinates.
When something looks inconsistent, stop and investigate instead of simply accepting a successful drawing.
There was also an unexpected lesson for Donald: sometimes a teacher discovers the next important abstraction at almost exactly the same moment as the student!
Theme
Think like a mathematician. Think like a programmer.
Don't just ask whether the program works.
Ask what it means, why it works, whether it is consistent, and whether there is a simpler way to express the same idea.
What exactly makes a drawing a recursive H?
Why are there three smaller H's rather than four?
What must be true about the position and size of every child H?
Can we describe the same construction without a turtle?
What happens if we change the scale factor from 1/2 to 1/3?
Can we generalize this idea to other recursive geometric patterns?
And one final observation:
Leo didn't say much during the investigation. But his turtle did a lot of talking. LOL.