Found in the files [entries|reading|network|archive]

[ userinfo | dreamwidth userinfo ]
[ archive | journal archive ]

Sun 2016-03-27 13:41
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’…

[xpost |]

[personal profile] mtbcSun 2016-03-27 13:52

smsf is smallest something?

Link Reply to this | Thread
[personal profile] mtbcSun 2016-03-27 13:53

Hmmm. And there's an f on the end of smsf and also perhaps g and j which are alphabetically close so perhaps it's part of that family.

Link Reply to this | Parent
[personal profile] simontSun 2016-03-27 13:58

Could be. There's also a second sheet containing a more optimised version of the same program (fusing the two loops and eliminating the pointless array, so we just keep running track of the best value seen so far as we go along), and that has variables smx and smy for the x-coordinate and total length.

Hang on – as I typed that paragraph, I realise that "so far" is quite plausibly the "sf" part of the name: "smallest so far". That must be it.

Link Reply to this | Parent | Thread
[personal profile] mtbcSun 2016-03-27 18:56

Ha, yes, indeed. (-:

Link Reply to this | Parent
[personal profile] pjie2Tue 2016-03-29 11:06

J could plausibly be "junction".

GG, on the other hand.... could this possibly be solving a puzzle from "Granny's Garden" or some such?

Link Reply to this | Thread
[personal profile] simontTue 2016-03-29 11:28

Interesting thought! But I never played Granny's Garden – I saw a machine running it once, when I was about 8, but didn't get a go.

(Also, wasn't it a Beeb-only game? I was a Spectrum baby.)

Link Reply to this | Parent
[ go | Previous Entry | Next Entry ]
[ add | to Memories ]