Friday, 11 March 2011

DNA Source Code

Today, should have been Douglas Noel Adams' 59th birthday.

It's a real pisser that we can't all clog up his @mentions column on Twitter with our best wishes, as it's fairly safe assumption that Douglas would have had a twitter account before Stephen Fry.

It is an important and popular fact that things are not always what they seem. For instance, Douglas is often quoted as being the first European to own an Apple Macintosh computer. (Narrowly pipping Stephen Fry to this momentous milestone). This may well be true, however, the highly frustrating Hitch Hikers Guide to the Galaxy computer game (did you ever get that bloody Babel fish out of the dispenser?) written by Douglas and Steve Meretzky first appeared in 1984 on a number of platforms including the Macintosh's humble predecessor, the Apple II.

By a strange coincidence I started my working life in 1984 as a computer programmer on the Apple II (actually it was an Apple IIe 32K with twin 5 1/4 inch floppy drives), not unlike this bad boy here:

It's now been well over 25 years since I last attempted to write a program for the Apple II, but I recently rediscovered this Applesoft BASIC reference manual, a copy of which used to adorn my desk as
it had already supplanted the great MITS Altair BASIC Reference Manual as the standard repository of all knowledge and wisdom.

Others of my age, who learnt to program on the Acorn BBC micro may notice a similarity as both machines were based on the 6502 microprocessor.

Looking back at this reference manual now, its seems frustratingly devoid of even the simplest language constructs. In fact, I recall that due to the lack of a simple boolean variable type, I frequently peppered my code with memory wasting statements like IF PINK$ = "FLOYD" THEN GOSUB X, for want of a simple binary switch.

Curiously, an edition of the Applesoft BASIC Reference manual which conveniently fell through a rift in the time-space continuum from 25 years in the past describes the manual as "frustratingly devoid of even the simplest language constructs."

Anyway, on the slight off-chance that I'm not the only DNA fanboy who also eked out a living in the early 1980's as a dodgy AppleSoft BASIC programmer, here's some utterly pointless and inefficient pieces of source code that I quickly cobbled together last night to remind you of both Apple's great advancements and literary's immense loss.


30 PRINT "I am at a rough estimate thirty billion times more intelligent than you."
40 PRINT "Let me give you an example."
50 PRINT "Think of a number, any number. ";
60 PRINT "Wrong. You see?"


30 PRINT "Enter 24 hour time in format ( ";
50 H$ = LEFT$(T$,2)
60 PRINT "Time is an illusion ";
70 REM double if lunchtime
80 IF H$ >=12 AND H$ <13 br="" print="" then="">


10 REM Vogan Grandmother attack checklist
40 PRINT "Do you have orders to save your Grandmother from the ravenous Bug-Blatter Beast of Traal? (Y/N): ";
50 GOSUB 300
60 PRINT "Have the orders been signed in triplicate? (Y/N)";
70 GOSUB 300
80 PRINT "Have the orders been sent in? (Y/N)";
90 GOSUB 300
100 PRINT "Have the orders been sent back? (Y/N)";
110 GOSUB 300
120 PRINT "Have the orders been queried? (Y/N)";
130 GOSUB 300
140 PRINT "Have the orders been lost? (Y/N)";
150 GOSUB 300
160 PRINT "Have the orders been found? (Y/N)";
170 GOSUB 300
180 PRINT "Have the orders been subjected to public inquiry? (Y/N)";
190 GOSUB 300
200 PRINT "Have the orders been lost again? (Y/N)";
210 GOSUB 300
220 PRINT "Have the orders been buried in soft peat for three months? (Y/N)";
230 GOSUB 300
240 PRINT "Have the orders been recycled as firelighters? (Y/N)";
250 GOSUB 300

260 PRINT "Resistance is useless"
270 END

300 INPUT A$
310 IF A$ <> "Y" THEN GOTO 400

400 PRINT "You are not authorised to lift a finger to save her"
410 END


10 DIM A$(3)
20 A$(0) = "Anything that happens, happens."
30 A$(1) = "Anything, in happening, that causes something else to happen, causes something else to happen. "
40 A$(2) = "Anything that, in happening, causes itself to happen again, happens again."


65 REM It doesn't necessarily do it in chronological order, though.
70 REM set x to a random value between 0 and 2
80 x = INT (3 * RND (1))
90 PRINT A$(x)

100 REM Set y to a random value between 0 and 2 other than the value of x
110 y = INT (3 * RND (1))
120 IF y = x GOTO 110
130 PRINT A$(y)

140 REM Set z to a random value between 0 and 2 other than the value of x or y
150 z = INT (3 * RND (1))
160 IF z = x GOTO 150
175 IF z = y GOTO 150
180 PRINT A$(z)

190 END

Incidentally, I did originally write this as a series of shorter and catchier snippets of pseudocode, just for shits n' giggles, but I feared a torrent of pedantry if I included any syntax or semantic errors, so I thought it best to ensure my code does actually compile (well, interpret to be precise, I never had the luxury of a compiler).

So I found this excellent little Javascript version of the Applesoft BASIC interpreter which works a treat. If you copy any of the above pieces of source code and paste it over the sample "Hello World" program, and press "run", it will actually work. Although of course, it doesn't actually achieve anything useful.

Feel free to send me your own pieces of DNA AppleSoft BASIC source code in the comments for me to try out. Especially if you know how to multiply 6 by 9 in base 13. I think we all know what the answer to that is.

Oh, and before I go, special thanks to Prof Brian Cox for a stirring Douglas Adams memorial lecture at the Royal Geographical Society last night. Super.

I might send this in to the Readers Digest, I hear they have a page for people like me.
Post a Comment