Guess the Algorithm

A few days ago while aimlessly surfing the world wide web’s waves, I came across [Vintage Basic.

](http://www.vintage-basic.net) I don’t even remember what weird tangent I had gone on to find it, perhaps something related to reading about Lisp and old computers, I don’t even know. While there, I saw their collection of old BASIC games. I felt so grateful, since I remembered them from my days as a child on my beloved Apple II/E. The computer still works, but a girl who will remain nameless (especially since I now host her blog) lost all the discs. I still feel rather annoyed about that, but this helped a little.

In the course of downloading and running these great old programs, I found guess.bas, a simple number guessing game. I wouldn’t have gotten it, except that I remembered it.

] catalog
A 005 GUESS.BAS

Does that conjure any memories for anyone? I recreated how it might look as best as possible. The game works very simply: you put in the maximum number, the computer picks a number between 1 and the maximum, and you enter your guesses. The computer tells you if you guessed too high or too low. Simple, right?

Two lines of code caught my eye, however.

<br /> 11 L1=INT(LOG(L)/LOG(2))+1<br /> 56 PRINT "YOU SHOULD HAVE BEEN ABLE TO GET IT IN ONLY";L1<br />

After getting the maximum number in the variable L, it assigns INT(LOG(L)/LOG(2)) to the variable L1. In other words, it adds one to the integer (whole number) part of log base 2 of L. Why, I wondered, did it use this value for the number of guesses it should take you to guess a number?

For those who slept in math, the logarithm refers to the exponent that indicates the power to which a base number is raised to produce a given number. For example, the logarithm of 100 to the base number of 10 is 2. Since I slept a lot in English class, I ripped that definition off from my dictionary. I thought about the relation between logs, exponents, bases, multiplication, division, anything I could think of that might solve this fun little mystery.

I took a shower, and my mind wandered. I began thinking about how I would actually solve the problem myself. If I had to choose a number between 1 and 10, I would first guess5, the halfway point. That way, the answer would automatically eliminate half the numbers. I would then continue this process, each time eliminating half, narrowing down until i guessed the number. I think most people would solve the problem in the same way. It then hit me! The integer part of log base 2 + 1 would roughly compute this number. It makes total sense! Think about it! To illustrate, if L=10, then L1=4.

I find it interesting to reflect on this. You can tell a lot about a person and the time period by analyzing code. That fragment told me that whoever wrote that dinky little program probably had a background in math or computer science. Today’s kids pumped full of Java probably don’t even know what a logarithm even does! I took standard math in high school, then in college I took three awful semesters of discrete math followed by two semesters of calculus – pure Hell. Any system that bases itself completely around limits just doesn’t jive with my world view. To me, such a proposition denies the limitless nature of the universe and the soul, but I digress. I love all the wonderful opportunities modern home computing has brought to the masses, but sometimes I long for the days when you actually had to KNOW about computers and have some command of programming and math to use one. I confess it took me a little to figure out this mystery, but I think I did. Many greater than myself have come before, and

many will come after. I saw an entire legacy encapsulated in two lines of code. Don’t forget.