Set the WABAC Machine for the late 1980s...
What's the first long running program you remember writing? One summer at the high school computing lab I saw the room full of PCs were sitting idle and thought it would be fun to write a program that would run for a long time.
Two math problems came to mind: 1. find prime numbers less than a bazillion, 2. compute pi to a bazillion digits. I chose the first one mainly because it would be relatively easy to verify. After all, if I found the 904th digit of pi was a 2, how was I going to verify it?
The only language I had available to me at the time was BASIC. Don't judge - that's what the school had and that's all I knew at the time. I didn't have much of an algorithm for finding primes, but I had a trusty For Loop and a lot of time. I don't think I have the code any longer, kinda wish I still did so I could try it now. My method was pretty simple: Increment a counter to the next number, start a loop up to 1/2 of that number and see if it divided evenly (quick, tell me what the big O notation of that would be). I'm sure there are better ways than just a loop inside a loop but this was a long time ago... You kids these days with your Google could probably find me a better algorithm.
I knew this program was going to run for days and could be subject to interruption (such as being unplugged by a janitor) but wanted to keep a good record of my results. My immediate choices were to periodically save to a file or send a line to the printer. Saving to the 5.25" floppy would have been fine I suppose, but I chose to use the printer because the progress would be more visible and permanent. After finding 10 prime numbers, my program would send one line to the printer listing them.
It ran for days (maybe a couple weeks) before it finally was interrupted. Every so often the printer sprang to life and added one line of prime numbers. Obviously it was quicker with the smaller numbers because it had smaller numbers. Eventually my program filled about 6 or 7 pages. I don't really remember how far it got, but I do remember being rather proud of the result. I taped the output up on the wall in my bedroom - I should call my mom and see if it's still there.
On the next episode of "Time to Reminisce" maybe I'll talk about the first program I wrote for somebody else.
0 comments:
Post a Comment