My son M, who is 7 years old, has decided he wants to learn to do computer programming, so my husband bought us a book called Land of Lisp. I went through and read the first few chapters and programmed in the first game that the book suggests. The game is called “guess my number” and the computer guesses the number the person is thinking of based on clues of “smaller” or “bigger.” It is pretty simple but the point is to learn how to program.
Of course nothing is ever simple in our house. The program works by telling the computer to add together the largest and smallest number possible and dividing that by two. The program starts with 0 and 100, so its first guess is always 50. 50 becomes the new minimum or maximum, depending on whether the person says bigger or smaller, so the next guess is either 25 or 75. Knowing how the computer was going to search makes it easy to choose which number should be the secret number. I graphed this out so you can see the choices. I was lazy, so I only did half the graph but the other half should be a mirror image. Arrows to the right shows a “bigger” answer and arrows to the left mean a “smaller” answer.
The search can take between 1 and 7 guesses, depending on where your number is. If your number was 50, it will take one. There are two options that can be guessed in two guesses. There would be four that take three guesses (only two shown). There would be eight that take four guesses, and 16 that take five guesses and 32 that take six guesses. If you’ve memorized the powers of 2, as I argued in a previous post people should do, then you will assume that there would be 64 guesses that take seven guesses, but there aren’t, because some of those possibilities have been eliminated already. So there are 37 guesses that will be guessed on the 7th guess. Added altogether, there are 101 possibilities (counting 0 and 100) but following the binary search pattern the possibility can be discovered in a maximum of 7 guesses. If you want the computer to have to make the maximum number of guesses, you choose one of those 37 guesses. Obviously our next task is to redo the program so that we will not know which path it is taking and once I master the random feature I’ll make a program where we have to guess the number the computer thinks up.
In the meantime, I discovered my four year old can enjoy playing the guess my number game with a number-line to a hundred and two pieces of lego. I showed him how to move the lego to show how making guesses changes the outer parameters and helps us narrow down the proper number.
The book on Lisp that we have includes little comic strips. One of them is dealing with how to tell the computer which element of a list you want. The code is cdr for “not the first” or car “the first” or some combination like cdadr which means “not the first, but then the first, but not the first of the options nestled within that”. The comic strip shows two crooks trying to plan how to rob a train referring to the locations on the train by using the Lisp code. That was an instant hit at our house and we quickly had drawings of train cars with security cameras and attempts to communicate locations using the code. At some point I want to try challenging the kids to think of other ways of communicating which item of a list we are selecting, so that we can get a better sense of the strength and weaknesses of using the lisp method.
I am hesitantly optimistic about the educational possibilities in learning Lisp. I know that sitting a seven year old down and lecturing him on a computer language won’t work, but that’s not the best way to teach the children anything. So instead today I pretended to be a robot and asked how they could program me to build with blocks. I explained that they could write a program that just lets me build with one material, or they could write one that could be applied to other materials too. “Material” became one of the variables they could tell the robot. They described different functions for building. One function would be stacking blocks, one would be covering gaps, one would be turning corners, one would be filling in the remaining pieces with small blocks. My four year old was lost, but the seven year old was keeping up. I showed him how in Lisp we feed the computer the variables by writing them in brackets in the same order as they are listed in the function definition. We used normal English as well as a few Lisp terms and I didn’t worry about keeping everything accurate. My goal was to work more on the grammar than the actual commands of Lisp.
Part of the reason I’ve gotten so excited about Lisp these past few days is that the programming language seems to work quite similar to the way my mind does. The language relies on lists and applying functions to the list. Some of the games the book teaches involve graphs and I’m already bursting with ideas for new games to start programming. I know the kids want me to do a text adventure game with them, where they write up a story and different possibilities and actions. We have the setting of one written but it will take a bit for me to learn enough programming to finish it, and to get them to look at the actions step by step enough.