My First "Hour of Code"

During the week of Dec 9-15th over a half billion lines of code were written for the hour of code initiative by over 20 million people.

Image of code on screen. From http://www.flickr.com/photos/rinoshea/7702900836/ use under CC-by-NC license

This got me reflecting on my own original "hour of code". It was a seminal moment in my life. I had never seen a real computer before this point in my life, much less ever programmed one. But one moment during my "hour of code" opened my eyes to the wonders of programming and set my career direction for life.

1976

Ok, this will date me. Between my Junior & Senior year in high school, I had the honor of attending a weeklong computer programming camp at my local state university (Stephen F. Austin).

Think back to 1976. Steve Wozniak had just built the Apple I computer board for hobbyist. Gary Kildall created CP/M which would become the most popular operating system until MS-DOS dethroned it a few years later. Punched cards were still in vogue. And in my small town in East Texas there was no computer access for a mere mortal in high school.

Wang Series 700

Our computer for the week was the Wang Series 700 Programmable Desktop Calculator. Lest the word "calculator" conjures up something you slide into your pocket, take a look at this beauty:

Wang Series 700 Programmable Desktop Calculator

By the power of the internet I was able to locate both an emulator and the original programming manual!

The emulator does the best job of clearly showing what my first programming experience was like.

Screenshot of the Series 700 Emulator

Programming the calculator was really more akin to assembly language programming. Two of the keypads have logic commands, program controls, and register manipulation.

Programming the Series 700

When you are in the "learn" mode pressing keys enters them into core memory registers and assigns the equivalent machine code to each instruction. You can think of the keys as the assembly language instructions that map to the appropriate program codes. Just like in any assembly language you spend your time being mindful of registers and where and when you put values and retrieve them.

Wang Series 700 programming pad

The key instructions for branching are Skip If Error, Skip If Y >= X, Skip If Y = X, and Skip if Y < X. The keys Mark and Search mark or goto a "named" line in the code.

Notice the display has two rows of numbers. The top row displays the Y-register. The bottom row displays the X-register.

Wang Series 700 programming keypads

The calculator also had a set of function keys that mapped to additional registers. The flip switches extended the range for a total of 120 registers.

Wang Series 700 programming keypads

You can control the values stored and retrieved in these registers with the register keypad.

Wang Series 700 programming pad

The calculator also included indirect addressing (putting a value in a register that is in turn the register address to store or retrieve a value).

Here is a typical program, complete with looping logic.

Wang Series 700 example program

My Hour of Code

As the week wound to a close we were given this challenge: given a sufficiently large number, write a program that would determine if the number was prime or not.

From my vantage point today, this seems like a pretty trivial problem to solve. But step into my 1976 shoes. No internet. No programming books (just the Wang programming manual). I had never seen a computer before nor had I programmed one before.

It was Thursday evening. The assignment was due the next day. After grabbing a quick bite to eat I headed over to the Computer Science Lab to start working on the problem in earnest. Of course the first approach I took was brute force. Iterate over all numbers (f) up to the number in question (x). Divide f into x and then look for a left over value (remainder). If I found a factor that divided evenly then the number was not prime. I realized quickly that I could divide the set of factors by 2 as an optimization.

Ok, simple enough I thought. I ran the program. It took a long time.

It was at this moment that I had an epiphany. The highest factor possible was a factor (f) that when multiplied times itself (f^2) would exceed the value of number x in question and thus be as far as I would need check as a factor! In other words I could just take the square root of the number (x) and try factors (f) up to that square.

When I ran the new program, instead of taking an hour to run, it only took a couple of minutes!

The next day was the real payoff. I ended up being the only one to complete the assignment. The instructor suggested we load my program, break for lunch and come back and check the result later since it would take a while to run. I mentioned that it actually should just take a couple of minutes. He gave me a look of disbelief but decided to humor me (he figured I had written a faulty program). We ran it and it finished in a couple of minutes with the right answer.

The look on his face was priceless. After class he took me to his office to encourage me to pursue a career in computer science. I have to say that this single experience shaped my love for computing and my belief that I could excel in this field.

It was this hour of coding that did it for me. That first exposure was magical.

(Of course I went home and could only code on paper and "play the computer" with all the new algorithms I was writing.)

The Beauty of Coding

That Thursday night I discovered the beauty of coding. The ability to come up with an algorithm that solves a problem and solves it more elegantly than what has come before (or at least what I knew of). Interestingly what I had stumbled upon is known as the Trial by Division Method which is a variation of the Sieve of Eratosthenes. Unknown to me, David Turner, the computer scientist, had devised a Trial by Division algorithm using functional programming in 1975 just a year before my amateur effort.

Of course these algorithms were discovered thousands of years ago. The Sieve of Eratosthenes is more efficent than Trial by Division. And in Eratosthenes' day the sieve was simpler than division (and a lot faster). But on the Wang Series 700 where memory was precious, Trial by Division was actually the better approach.

For those interested there are many improvements over my very simple algorithm. And prime factorization is a key component of cryptology and remains a fascinating area of computer science and math to study.

Your Hour of Code

If you haven't had your hour of coding or know someone who you would like to have that magical moment, send them over to Learn to Code or Khan Academy start learning to code.

Do you have an hour of coding story?

This article's cover image is from Flickr used under the creative commons by-nc-sa license