The function mapFolding.countFolds()
counts distinct ways to fold maps and strips of stamps. The function accepts two or more dimensions:
from mapFolding import countFolds
foldsTotal = countFolds( [2,10] )
The directory mapFolding/reference has
- a verbatim transcription of Lunnon's "procedure" published in 1971 by The Computer Journal,
- multiple referential versions of the procedure with explanatory comments including
- hunterNumba.py, a one-size-fits-all, self-contained, reasonably fast, contemporary algorithm that is nevertheless infected by noobaceae ignorancium, and
- miscellaneous notes.
mapFolding
directly implements some IDs from The On-Line Encyclopedia of Integer Sequences (BibTex citation).
After installing (see below), OEIS_for_n
will run a computation from the command line.
(mapFolding) C:\apps\mapFolding> OEIS_for_n A001418 5
186086600 distinct folding patterns.
Time elapsed: 1.605 seconds
Use getOEISids
to get the most up-to-date list of available OEIS IDs.
(mapFolding) C:\apps\mapFolding> getOEISids
Available OEIS sequences:
A001415: Number of ways of folding a 2 X n strip of stamps.
A001416: Number of ways of folding a 3 X n strip of stamps.
A001417: Number of ways of folding a 2 X 2 X ... X 2 n-dimensional map.
A001418: Number of ways of folding an n X n sheet of stamps.
A195646: Number of ways of folding a 3 X 3 X ... X 3 n-dimensional map.
Usage examples:
Command line:
OEIS_for_n A001415 8
Python:
from mapFolding import oeisIDfor_n
foldsTotal = oeisIDfor_n('A001415', 8)
Use mapFolding.oeisIDfor_n()
to compute a(n) for an OEIS ID.
from mapFolding import oeisIDfor_n
foldsTotal = oeisIDfor_n( 'A001418', 4 )
Clear The On-Line Encyclopedia of Integer Sequences data from the mapFolding
cache:
(mapFolding) C:\apps\mapFolding> clearOEIScache
Cache cleared from C:\apps\mapFolding\mapFolding\.cache
The full paper, W. F. Lunnon, Multi-dimensional map-folding, The Computer Journal, Volume 14, Issue 1, 1971, Pages 75–80, https://doi.org/10.1093/comjnl/14.1.75 (BibTex citation) is available at the DOI link. (As of 3 January 2025, the paper is a PDF of images, not text, and can be accessed without cost or login.)
In foldings.txt
, you can find a text transcription of the algorithm as it was printed in 1971. In foldings.AA
, I have corrected obvious transcription errors, documented with comments, and I have reformatted line breaks and indentation. For contemporary readers, the result is likely easier to read than the text transcription or the original paper are easy to read. This is especially true if you view the document with semantic highlighting, such as with Algol 60 syntax highlighter.
archmageirvine (BibTex citation) says about the Java code:
/**
* A001415 Number of ways of folding a 2 X n strip of stamps.
* @author Fred Lunnon (ALGOL68, C versions)
* @author Sean A. Irvine (Java port)
*/
...
// Implements algorithm as described in "Multi-dimensional map-folding",
// by W. F. Lunnon, The Computer J, 14, 1, pp. 75--80. Note the original
// paper contains a few omissions, so this actual code is based on a C
// implementation by Fred Lunnon.
This caused my neurosis: I enjoyed the following video, which is what introduced me to map folding.
"How Many Ways Can You Fold a Map?" by Physics for the Birds, 2024 November 13 (BibTex citation)
pip install mapFolding