This is the same case given above, but expanded just slightly to demonstrate that the names of the relations can also be printed, if we like:
"Number Study"
Abstraction is a room.
Parity relates a number (called N) to a number (called M) when N minus M is even.
Joint magnitude relates a number (called N) to a number (called M) when N plus M is greater than 7.
To chart (R - a relation of numbers):
repeat with N running from 1 to 5:
repeat with M running from 1 to 5:
if R relates N to M, say "[N] <=> [M] by [R][line break]";
When play begins:
let L be { parity relation, joint magnitude relation };
repeat with R running through L:
chart R.
As this shows, we can even form lists of relations. The kind of L is "list of relations of numbers".
Fibonacci (a posthumous nickname) spread Arabic mathematical learning across Europe in the 13th century, and it's curious that his name lives on only for a single sequence.
"The Fibonacci Sequence"
Pisa is a room. Leonardo Fibonacci is a man in Pisa. "The modest Italian mathematician, Leonardo Fibonacci (1170-1250), beams at you."
Sequencing is an action applying to one number. Understand "sequence [number]" as sequencing.
Instead of sequencing, say "You make a feeble attempt, sketching in the sand, but it goes nowhere. Leonardo is sympathetic. 'Often goes wrong for me, too, actually. I didn't even invent the thing - the ancient Indians knew about it first.'"
Persuasion rule for asking Leonardo to try sequencing: persuasion succeeds.
Report Leonardo sequencing:
let N be the number understood;
say "Leonardo scratches his head and makes self-deprecating remarks, before coming up with [the first N terms of the Fibonacci sequence]."
An array need not be fixed in length, as the following example shows:
To decide what list of numbers is the first (F - a number) terms of the Fibonacci sequence:
let the Fibonacci sequence be {1, 1};
let N be 3;
while N < F:
let the last term be entry (N - 1) of the Fibonacci sequence;
let the penultimate term be entry (N - 2) of the Fibonacci sequence;
let the next term be the last term plus the penultimate term;
add the next term to the Fibonacci sequence;
increment N;
decide on the Fibonacci sequence.
Test me with "sequence 20 / leonardo, sequence 20".
The result of "the first 20 terms of the Fibonacci sequence" is "1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584 and 4181". This is a sequence which has a knack of turning up in odd places - it was found in the 1970s to be related to the rings of florets in a sunflower, for instance - and here it is in a book about interactive fiction.
In the words of Wikipedia: "Eratosthenes of Cyrene (Greek Eρατοσθένης; 276 BC-194 BC) was a Greek mathematician, poet, athlete, geographer and astronomer." In the words of Tom Lehrer: "It's people like that who make you realise how little you've achieved in life."
A prime number is a number greater than 1 which is not a multiple of anything, so we can find the primes by starting with all the numbers and sieving out all the multiples of 2, then all the multiples of 3, and so on. Here we make our sieve of the unacceptable numbers (the "composite" or non-prime ones) first, then form a list of all the numbers, then sieve out the composites: what are left must be the primes.
"Sieve of Eratosthenes"
Alexandria is a room. Eratosthenes is a man in Alexandria. "The haughty Greek mathematician, Eratosthenes, glowers at you."
Sieving is an action applying to one number. Understand "sieve [number]" as sieving.
Instead of sieving, say "You make a feeble attempt, sketching in the sand, but it goes nowhere. Eratosthenes smirks. 'I expect your friends call you gamma, then?'"
Persuasion rule for asking Eratosthenes to try sieving: persuasion succeeds.
Report Eratosthenes sieving:
let N be the number understood;
let the composites be a list of numbers;
let I be 2;
while I times I is at most N:
if I is not listed in the composites:
let J be I times 2;
while J is at most N:
add J to the composites, if absent;
increase J by I;
increment I;
sort the composites;
let the primes be a list of numbers;
repeat with P running from 2 to N:
add P to the primes;
remove the composites from the primes;
say "Eratosthenes sketches lines in the sand with the air of much practice. 'The primes up to [N] are [the primes]. The composites are [the composites].'"
Test me with "sieve 10 / eratosthenes, sieve 100".
While this could all be done more efficiently with an array, that's only because what we are sieving are numbers: sieving is a technique which can be used for non-numerical decisions, too.