**Found in the files**
I visited my mum yesterday, and we ended up going through a box file of snippets she'd saved from my childhood. Among them, printed on silvery ZX thermal printer paper that brought a nostalgic smile to my face in its own right, was the following Sinclair BASIC program, printed together with its output. ` 5 BORDER 0: PAPER 0: INK 7: CLS` 10 DIM x(40) 20 FOR z=1 TO 40: LET a=z*0.1 30 LET y=SQR (1+(a*a))+SQR ((4-a)*(4-a)+4) 40 LET x(z)=y 50 NEXT z 60 LET smsf=1 70 FOR z=1 TO 40: LET a=z*0.1 80 IF x(smsf)>x(z) THEN LET smsf=z 90 NEXT z 95 PRINT "GG end to J", "Road length" 100 PRINT smsf,x(smsf)
`GG end to J Road length` 13 5.0001815
I don't know why Mum chose to save that program in particular, out of all the ones I must have printed out in the few years I had the Spectrum and that printer. She guessed that it must have been the first one I wrote, but it seems a bit sophisticated for that – surely there would have been a pile of ‘hello, world’ type things before this quite mathematical one? Regardless, I had completely forgotten it, and it makes me smile at the fact that what it seems to be doing is *numerically testing* the proposition that a straight line is the shortest distance between two points. (Line 30 calculates the distance from (0,0) to (4,3) via the point (a,1); the rest of the program tries this for lots of different values of a, and finds the one that gives the shortest total distance, which unsurprisingly is the point where the straight-line route intersects the line y=1, to the limits of rounding error.) But I do wonder whether this was something I typed in from elsewhere in full, or followed hints in a manual, or what. I'm particularly curious about the variable name `smsf` and the cryptic legend ‘GG end to J’… |