I am reading Godel, Escher, Bach: An Eternal Golden Braid by Douglas R. Hofstadter. First published in 1979, the author discusses various systems – mathematical, visual and musical, which somehow manage to talk about themselves. This self-reference, says the author, is one of the key ingredients for intelligence.
Much of the book so far has been taken up with explaining some key elements of number theory, and Hofstadter includes lengthy digressions on programming, and loops of operations nested within others. It inspired me to find a BBC BASIC emulator and write a little programme that finds prime numbers. Here is what I came up with:
20 PRINT "LIMIT";
30 INPUT L
40 FOR N = 3 TO L
50 FOR D = 2 TO (N-1)
60 IF N/D=INT(N/D) THEN GOTO 100
70 NEXT D
80 PRINT N;
90 GOTO 110
100 PRINT ".";
110 NEXT N
This programme asks you for a number, and it will search for prime numbers up to and including the number you give. If it finds a prime, it prints it, otherwise it just prints a dot. I chose this method of output so that one has a visual representation of how primes are distributed throughout the natural numbers, and it is easy to spot Twin Primes.
Since we’re thinking about self-reference, I might as well make an observations about this post, which is that it will probably succeed in alienating everyone. Those with no interest in maths and coding will likely think I am being terribly geeky. Meanwhile, those who do take an interest in such things will scoff at the incredible simplicity of my coding ambitions. Already one wag in the office has asked me why I don’t print all the discovered primes in an array…