A notebook with its own helper code
A notebook that imports its longer functions from _code/helpers.py beside it, and reads a data file: a document is a folder.
programmingnumber theorysagebrushDownload (ZIP)Source on GitHub
Preview
A notebook with its own helper code
This notebook is a folder: main.ipynb, and beside it _code/helpers.py (its longer functions) and data/fermat.txt (a small table the helpers read). The notebook imports its helpers like any Python module, because its folder is where it runs and the first place Python looks.
Download or share it with its files, and they all come along.
from _code import helpers
helpers.sieve(60)[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59]
Fermat thought every was prime. The helpers read from data/fermat.txt; Euler found the first that isn't.
for k, F in enumerate(helpers.fermat_numbers()):
print(k, F, helpers.factor(F))0 3 [3] 1 5 [5] 2 17 [17] 3 257 [257] 4 65537 [65537] 5 4294967297 [641, 6700417]
Which start below 1000 takes the longest to reach 1 under the Collatz map?
n = max(range(1, 1000), key=helpers.collatz_length)
n, helpers.collatz_length(n)(871, 178)
To change a helper, open _code/helpers.py in its own tab, edit it, and run the notebook again from the top.
Files
main.ipynb(2203 bytes)_code/__init__.py(68 bytes)_code/helpers.py(1327 bytes)data/fermat.txt(79 bytes)