A good introductory video by Mathologer on YouTube.
A very detailed explanation and proof of the various algorithms for generating number walls is available here.
A paper relating to properties of number walls that includes many examples of them which are used in the tests and examples is available here.
The best explanation is to look at some of the code in the examples directory.
In short:
- Initialise a holder with a sequence (or function), and bounds as to which values you would like from that wall.
- Call the
calculate_next_line
function to calculate the next line of the wall. - Get the contents of that line with
get_last_line
. - Repeat steps 2 and 3 until all of your requested lines have been calculated, and
calculate_next_line
returnsNone
.
There are 3 types of wall available:
- bi directional: the most traditional form of number wall. A sequence (or function) is used for positive and negative values.
- left const: these walls have constant values in positions -2 and -1, this allows for positive only sequences (or functions) to be calculated, although you may get unexpected or strange results below the leading diagonal.
- repeating sequence: optimised for periodic sequences, the left and right edges of the wall wrap around to each other, to allow fewer values to be computed.
See the examples in the images directory.
Only the last line is available as once a line is no longer needed for future calculations it is dropped to save memory.
The program is fairly fragile, most input errors are handled by panic!
.
You may get errors using strange left values for the left const wall, as they could potentially create invalid walls (maybe?), however I haven't tested this.
Add a WallHolder
trait including the calculate_next_line
, get_last_line
, get_line_count
and get_line_memory
functions to reduce code reuse for programs using multiple types of wall.