Skip to content

SudhamshM/Collatz_Conjecture_Graph_Steps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Collatz_Conjecture_Graph_Steps

This is my first GitHub project, and I saw a video (https://www.youtube.com/watch?v=094y1Z2wpJg) by Veritasium about the Collatz Conjecture, so I wanted to write a Python program that calculates the steps it takes for a number to reach 1 using the Collatz Conjecture rules.

You start with any positve integer (the "Original" number). Check if it is even or odd.

If the Original is odd, you multiply it by 3 first and then add 1 to it to give you the next number. If the Original is even, you divide it by 2 to give you the next number.

You continue this process for this next number and eventually it seems you should end back down at 1.

For example, the Original using 2, we will divide by 2 to give you 1, and this took 1 step. The Original using 3, we will multiply by 3 and add 1, it will yield 10, and it goes down to 5 by halving. Then, it goes to 16, and then 8, and then 4 and 2 and 1.

Run this program to see how your Original differs and how many steps it takes. Check the screenshot for an example!

Also, I added a plot graph if you want to see the steps your Original number takes while it is operated throughout the program.

Let me know where I can improve.

Thank you!