Python program testing the Collatz Conjecture, also known as the 3n+1 problem.
The Collatz Conjecture is a conjecture in mathematics that concerns a sequence defined as follows: start with a positive integer n. Then each item is obtained from the previous term as follows: if the previous term is even, the next term is one half of the previous term. If the previous term is odd, the next term is 3 times the previous term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
For more info: Wikipedia
I am writing a program that will confirm that when the Collatz Conjecture is applied to positive integers, the sequence will end with 1. This is not a proof. For more information on why the conjecture is not proven, see the link above.
The program flow:
- Take a starting positive integer
- Determine if the integer is even or odd
- If even, divide the integer by 2
- If odd, multiply the integer by 3 and add 1
- Check the result: if 1 end, else repeat
usage: collatz [-h] [-t] [-w] N
Compute the Collatz-Conjecture
positional arguments: N The starting integer to compute from
options: -h, --help show this help message and exit -t, --trajectory Display the highest number (trajectory) in the list -w, --wide Display the list horizontal rather than vertical
collatz.py is licensed under the GNU General Public License v3.0 or later
See LICENSE to see the full text.
- Do more than just print results to screen; maybe write to a file
- Integrate with a db to catalog all sequneces created