GP code examples for generating sequences

A note on "print" versus "write" in GP: when generating a sequence in GP, you can use the write command to output to a file. This, however, is often slow, since it requires opening the file for every term of the sequence. A quicker method is to use the tee command (in any unix-like environment) and call gp like this:

gp | tee output.txt 

This will start gp, but all output will be echoed to the file output.txt. Then, you can do something like


to spit out all primes under 106 to the screen. Then quit gp, and open output.txt in a text editor and you will see all the primes there. Remove any extraneous lines, save, and you'll be ready to feed it to the score-from-list code.

Here is some GP code which generates the sequence of integers whose digits sum is 12 ( A235151).


Here is some GP code which generates the sequence of abundant numbers (A005101).


Here is some GP code whcih generates the Sophie Germain primes (A005384). The 78498 values is arrived at by noting that the 78498th prime is the largest one less than 106.