Can a turtle draw your face?

Turtle used to show kids in intuitive ways how programming works
Turtle used to show kids in intuitive ways how programming works
Listen to this article |
When I was younger, so much younger than today, we had a tortoise as a pet. In tribute to the great mathematician of ancient Greece, we named him Archimedes, Archie for short. He was a charmer, chomping on hibiscus flowers and lettuce, occasionally delivering a nip on a nearby toe. He was also given to wandering about outside our home to check on any flowering plants, turning this way and that, seemingly at random as he went. He was not, let it be said, a turtle. Those are water animals. Archie lived and wandered exclusively on land. Be that as it may, I’ve had Archie on my mind all through a recent encounter with a turtle. Or, I should say, Turtle.
Turtle is a system that’s used to show kids in simple, intuitive ways how programming works. It was originally part of an educational programming language called Logo that Cynthia Solomon, Wally Feurzeig, and Seymour Papert had invented in the late 1960s. For people like me, who came to programming in the decade or two after that, Turtle and Logo were part of the conversation in our classes, offices, and labs. This was true even though we worked in more complex languages like Lisp, C, and Prolog—because we understood the value of those simple, intuitive ways.
In essence, Turtle lets you draw shapes and pictures by issuing instructions to a small simulated turtle. For example, if you tell it to move forward a centimetre, it draws a line that’s one centimetre long. If you then tell it to turn 90 degrees to the left and move forward another centimetre, it draws another line that’s a centimetre long, at a 90 degree angle with the first. There’s a start at a picture, though of course the hope is for more interesting ones than just two lines that meet at right angles. So “move forward a given distance" and “turn anticlockwise through a given angle" are two Turtle instructions. There are two more: “pen down" and “pen up". In the example above, the two lines get drawn because you actually said “pen down" to the turtle to start with. You would use “pen up" before another move instruction—for example, if the pen must move to a new location without drawing a line.
Clear so far, I trust? Now suppose you give Turtle this series of instructions: pen down, move forward one centimetre, turn 90 degrees anticlockwise, pen up. Suppose you tell Turtle to do this set four times. Think of it: You have produced a square one centimetre on each side. The turtle is back where it started. What’s more, you’ve put together a programme—this instruction set, repeated four times—that if simple, is nevertheless a step into the world of programming. For a programme you write for a computer is really just a series of instructions, some possibly repeated some number of times, some possibly dependent on the outcome of others, etc.
And if this is how you get Turtle to draw a square, you can work out how to make it draw a triangle, a hexagon, or a rectangle with both diagonals marked. As you work out those, you’ll learn how to programme even more complicated images: a pyramid, a house, the skyline of a city ... maybe even a face?
Ah, and there lies a story. Stay with me.
Only a few days ago, the popular Youtube channel Numberphile put out a couple of videos that feature a version of Turtle. In them, Matt Henderson, a mathematician in Edinburgh, plots some intriguing Turtle curves, driven by numbers. This is how that works. Assume a “pen down" at the start, so the turtle will always draw something as it moves. Assume also a default “move forward one centimetre" instruction. That is, every time the turtle turns through some specified angle, it then draws a line one centimetre long. Now Henderson divides the 360 degrees of a circle into ten equal arcs, each spanning an angle of 36 degrees. He labels them from 0 to 9; that is, 0 means a turn anticlockwise through 0 degrees, or not at all; 1 means turning 36 degrees; 2, 72 degrees; and so on. He sets up Turtle to understand and act on the digits in this way.
Think of what happens when you feed Turtle a series of digits. If we start with the turtle facing horizontally right and then offer it 0, 2, and 1, what do we end up with? We get three lines, each a centimetre long; the first is horizontal, the second forms an angle of 72 degrees (36 x 2) with the first, the third an angle of 36 degrees with the second. What of several 5s? The first makes the turtle turn 180 degrees (36 x 5) and draw a line going horizontally to the left. The second 5 turns it 180 degrees again, so it moves to the right this time, going over the same line. Thus several 5s leave us with just that one line. Similarly, you can see that several 0s produce a long horizontal line stretching to the right.
You get the picture now. So Henderson gave Turtle various sequences of digits. Like the decimal expansion of 1/7, or 0.142857142857... It results in a stylized symmetrical flower, with a certain pattern that repeats after a point. Or the decimal expansion of 1/119, 0.00840336...— another elegant flower-like creation, with a different pattern that repeats. The point here is that any number like this that can be expressed by a fraction formed by two integers—“rational" numbers, whose decimal expansions either end somewhere or have a sequence of digits that repeat ad infinitum—will produce those symmetric shapes with repeating patterns.
Which raises the question, what about an irrational number? Remember that the decimal expansions of irrationals never end and never settle into repetitions. Henderson fed the digits of one such, p (3.1415926...), to his Turtle. The result—this visualization of p, if you like—is nothing you would describe as elegant, with no symmetry and no obvious repeating patterns. It’s a “nice way to see the stark difference between rational numbers and irrational numbers", Henderson remarks.
And yet, as the turtle waddles through thousands of digits of p—or other irrationals—the diagram begins to take on a strange charm of its own, sometimes even hinting at exotic shapes. Is that the Indian subcontinent? The island of Britain? The Mona Lisa?
So you wonder: if Turtle’s turtle uses p to draw like this without end, will it eventually produce a face? If what Turtle produces is a visual representation of p, is the Mona Lisa encoded, in this Turtle sense at any rate, somewhere in the digits of p? This is why Henderson ends his clip by wondering himself, “Can somebody send me the number that draws my face?" Within days, Felix Engelmann, a postdoc from Copenhagen, did just that. His number that produces a passable impression of Henderson is ... over 250,000 digits long.
And what of Archie our elegant tortoise? Someone found him wandering in the garden and, assuming he was doing Archie a favour, assumed too that he was a turtle. He took Archie to the sea. He threw him in. We mourned for months.
Numberphile video with Matt Henderson and Turtle
Dilip D’Souza now lives in Mumbai and writes for his dinners. His Twitter handle is @DeathEndsFun
Never miss a story! Stay connected and informed with Mint. Download our App Now!!