## The Ant and The Grasshopper

A computational fairytale updated for the computer age, a grasshopper learns algorithms and planning ahead.

One summer day, a grasshopper came upon an ant who was collecting grain. The grasshopper watched as the ant struggled to remove a kernel from a fallen stalk. After a few minutes, the grasshopper spoke.

“Little ant, what are you doing?” the grasshopper asked.

“Collecting food for the winter,” responded the ant in a weary voice. He was exhausted from a day of hard labor.

“But it’s the middle of the summer,” said the grasshopper. “Winter isn’t for months, and food is plentiful. Why do you spend your day like this?”

The ant paused for a moment while he thought. “It’s the algorithm that we use,” he finally replied.

“A set of steps or instructions for accomplishing a task,” explained the ant. “Like when a carpenter builds a chair, he uses an algorithm that includes measuring, cutting, smoothing, and hammering.”

“What task does your algorithm solve?” asked the grasshopper. “Does it solve the problem of having too much time during the summer?” He chuckled out loud at his own joke.

“It accomplishes the task of keeping the colony healthy all year round. Everyday, we have a set of tasks that we perform. During the summer we spend the mornings collecting food, the afternoons digging tunnels, and the nights sleeping. It might not sound like much, but it ensures that we have food during the cold winter.”

“That sounds like a simple algorithm,” said the grasshopper.

“Algorithms can be simple or complex,” explained the ant. “They can even include steps that require other algorithms to solve. For example, when I collect food, I use a special food collection algorithm. It has five steps: 1) walk to the field, 2) search for a wheat stalk with grain on it, 3) remove a kernel of grain from the stalk, 4) carry the grain back to the ant hill, and 5) place the grain in the storage tunnel. I follow those exact steps to collect a giant pile of grain.”

“That sounds boring,” said the grasshopper. “I don’t use algorithms. I just do whatever I want, whenever I want. Complete freedom. In fact, I think I’m going to climb to the top of the wheat stalk and sing for a while. I bet your algorithm doesn’t let you do that.”

The ant shrugged in response. He had his algorithm, and thus his next steps. This had worked for his colony for hundreds of years. While the grasshopper jumped away singing, the ant returned to his task.

### Epilogue

Six months later, a harsh winter engulfed the land. The grasshopper scavenged the frozen, bare wheat field for food. There was not a single kernel to be found.

At the same time, the ant was safe and warm in his colony’s tunnels. He was hard at work following his winter day algorithm, which consisted of: digging tunnels, eating, and relaxing. He greatly preferred the winter algorithm to the summer one. As he worked on extending the eastern food tunnel, he paused and thought back to the grasshopper. He wondered if the grasshopper was still spending his days singing in the wheat fields, or whether he had learned the value of a good algorithm.

If you liked this story, the author has written many more collected in several books linked below, including in July 2016 Search: A Tale of Algorithms, Computation, and Conspiracy. This story is reprinted with permission of the author, Jeremy Kubica.

#### The CS Detective: An Algorithmic Tale of Crime, Conspiracy, and Computation

To be released July 2016, you can order early and get a discount.
https://www.nostarch.com/searchtale

#### Best Practices of Spell Design

http://www.amazon.com/Practices-Spell-Design-Jeremy-Kubica/dp/1481921916

#### Computational Fairy Tales

http://www.amazon.com/Computational-Fairy-Tales-Jeremy-Kubica/dp/1477550291/

#### SmallTalks: Jeremy Kubica and Computational Fairy Tales

https://vimeo.com/70188494

## Author

• Jeremy Kubica is a principal engineer at Google. He has a B.S. in Computer Science from Cornell University and a Ph.D. in Robotics from Carnegie Mellon University. He is the author of Computational Fairy Tales, Best Practices of Spell Design, and the Computational Fairy Tales blog.

### Also In The June 2016 Issue

Tinkercad makes it easy to create and print 3D objects from your designs and designs others create.

Bakuro puzzles are a fun way to learn about binary numbers and how to calculate their values.

Figuring out how to find prime numbers is a matter of the right strategy plus code plus trying different ideas.

There are many ways to learn technology while playing. Here are technologies and resources you might want to find online this summer.

A super portable version of Makey Makey, there's lots of experiments you can do with the new Makey Makey Go!

A computational fairytale updated for the computer age, a grasshopper learns algorithms and planning ahead.

A book about the daily life of many different programmers who do neat things with code.

The US Congressional App Challenge is an annual contest to encourage US high school students to try programming by creating an app.

The Alda programming language lets you write and play music on your computer by typing simple commands.

Younger kids can have lots of fun playing games this summer while learning basic programming concepts.

Minecraft is a fun game to explore with a vast set of worlds, animals, and adventures. Here are ideas to continue the adventure, online and offline.

Battery history is a critical part of the history of technology. Without stored electricity, there would be no electronics.

Links from the bottom of all the June 2016 articles, collected in one place for you to print, share, or bookmark.

Interesting stories about computer science, software programming, and technology for June 2016.

A Swiss-made robot, Thymio robots work with drag and drop languages and text-based languages like JavaScript.

Interested but not ready to subscribe? Sign-up for our free monthly email newsletter with curated site content and a new issue email announcement that we send every two months.

No, thanks!