§10.11. Mathematics

It is uncommon, but not absolutely unheard-of, to need to do detailed mathematical calculations in interactive fiction.

The Fibonacci Sequence demonstrates the calculation of a series of numbers; Sieve of Eratosthenes shows off how to calculate the prime numbers within a certain range.

Number Study demonstrates conditional relations between numbers.


arrow-up.pngStart of Chapter 10: Physics: Substances, Ropes, Energy and Weight
arrow-left.pngBack to §10.10. Magic (Breaking the Laws of Physics)
arrow-right.pngOnward to Chapter 11: Out Of World Actions and Effects: §11.1. Start-Up Features

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:

paste.png "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".

*ExampleNumber Study
The parity and joint magnitude relations explored.

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:

paste.png "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".

*ExampleSieve of Eratosthenes
The haughty Eratosthenes of Cyrene will nevertheless consent to sieve prime numbers on request.

*ExampleThe Fibonacci Sequence
The modest Leonardo Fibonacci of Pisa will be only too happy to construct his sequence on request, using an array.