As a reasonably bright youngster in the early days of school computing, my idea for a first program was quite ambitious. I had started to learn the guitar, so I thought it would be cool to do some computer-generated music. I made a list of guitar chords and drew up a two-dimensional table of conditional probabilities for one chord followed by another. So for example, a D7 might have a 60% chance of being followed by a G, a 20% chance by a C and a 20% chance by an A7. For a G, it might have been 30% C, 20% E minor, 20% D7, 20% A minor and 10% B minor. The program would run in a loop, starting with a particular chord in the set, and generating subsequent chords randomly according to the probability table. I was fascinated by the idea of changing this table and seeing whether the music that came out would have a different "feel". Reasonably advanced stuff in those days (or so I like to think)!
This project immediately set me apart as an awkward customer, because I needed a random number generator. I can't remember how I did that in the end, but I don't think it was a built-in function. What I do remember, with pride and embarrassment in equal measure, is the results of my efforts. Pride because, of the ten or so of us, my printout was the only one that came back first time without any compilation errors. But embarrassment because there didn't seem to be any output at all. My teacher and I thought this must be a one-off problem, so we re-submitted the code with no changes (we didn't think of inserting "hello world" print statements or anything like that). Back it came the following week, same problem. Nothing! When the same thing happened the third time I noticed that the printouts did have something on them: a black rectangular blob in the top left corner. Here is the explanation: I had chosen to output my chords as single-digit numbers (dealing with characters and strings seemed too hard for a first program). A chord would be printed each time a print statement was encountered in my loop. Normally, that would produce a new chord on each line. But I wanted to save paper and print the chords across the page. I had been told that the "+" control character would make the next piece of output appear on the same line. But what I had not appreciated was that there was an implicit carriage return as well. So the 50 chords I asked for were indeed printed - all on top of each other! The following week I had my first readable output and I remember playing my first piece of computer-composed music - which has been lost to posterity.
My second project was much more ambitious, and never properly completed. It just had to be computer chess. That was a tall order in those days. I just about managed to write a program to play legal chess, but did not make much progress on getting it to play well!
This project immediately set me apart as an awkward customer, because I needed a random number generator. I can't remember how I did that in the end, but I don't think it was a built-in function. What I do remember, with pride and embarrassment in equal measure, is the results of my efforts. Pride because, of the ten or so of us, my printout was the only one that came back first time without any compilation errors. But embarrassment because there didn't seem to be any output at all. My teacher and I thought this must be a one-off problem, so we re-submitted the code with no changes (we didn't think of inserting "hello world" print statements or anything like that). Back it came the following week, same problem. Nothing! When the same thing happened the third time I noticed that the printouts did have something on them: a black rectangular blob in the top left corner. Here is the explanation: I had chosen to output my chords as single-digit numbers (dealing with characters and strings seemed too hard for a first program). A chord would be printed each time a print statement was encountered in my loop. Normally, that would produce a new chord on each line. But I wanted to save paper and print the chords across the page. I had been told that the "+" control character would make the next piece of output appear on the same line. But what I had not appreciated was that there was an implicit carriage return as well. So the 50 chords I asked for were indeed printed - all on top of each other! The following week I had my first readable output and I remember playing my first piece of computer-composed music - which has been lost to posterity.
My second project was much more ambitious, and never properly completed. It just had to be computer chess. That was a tall order in those days. I just about managed to write a program to play legal chess, but did not make much progress on getting it to play well!
No comments:
Post a Comment