collatz
Mathematical Programming with Python
https://people.sc.fsu.edu/~jburkardt/classes/...
python_2025/collatz/collatz.html
collatz:
the Collatz conjecture suggests that a simple operation, starting
at any integer and repeated indefinitely, will always end at 1.
It is interesting to determine how long it takes a particular
starting point to reach 1. Also, from a given starting point, the
sequence of iterates can sometimes increase very high before returning
to earth. We can use a Python dictionary (a new datatype we don't
actually know about yet) to update a table of our results. For some
related sequences, the "Mollatz", "Nollatz" and "Pollatz" sequences,
it is possible to say something definite about the convergence from
any starting point.
Lecture notes:
A short article from Quanta:
-
collatz.py,
given n, applies the Collatz transform, returning T(n).
-
collatz_sequence.py,
given n, repeatedly applies the Collatz transform until
reaching 1, and prints each value as it is encountered.
-
collatz_list.py,
given a value of n, repeatedly applies the Collatz transform
until reaching 1, and returns the entire sequence as a list.
-
collatz_numpy.py,
given a numpy array of one or more values of n,
returns a numpy array of the Collatz transform of each value.
-
collatz_dict.py,
for a given starting value n, adds each step of the Collatz
sequence to a dictionary of values ( n : T(n) ).
Last revised on 13 January 2025.