This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

TheGoldenProof presents ...


Collatz Calculator

Enter a number and it will spit out ever step it took to get to one and the number of steps it took.

The Collatz Conjecture: If a number (n) is odd multiply by 3 and add 1. If its even, divide by two. You will always reach 1.
Watch this video by numberphile about it:

5026 views / 1616 in the last 7 days

1 vote | 0 in the last 7 days

Tags: game simulation with-source math calculator collatz

open in greenfoot
Your browser does not support the canvas tag.


And 463 takes 128 steps, reaching as high as 9232 before coming down. The number 73 goes up to the same height, taking 115 steps. In fact, the others I had mentions (47, 97 and 107) all reach a maximum of 9232 -- curious.
@danpost the video in the description explains why. Two numbers steps may end up at the same result. for instance if you start at 10 you will get 10 -> 5 -> 16 -> 8 - > 4 -> 2 -> 1, and if you start at 21 you will get 21 -> 64 -> 32 -> 16 -> 8... and so on. Heres a small example:
You'll notice all of those numbers steps contain 107 as the first common number, so everything after 107 is all the same, and with that, you can take and number and, say you wanted to get 50 steps, find the (nSteps - 50)th number up there.


I can understand numbers closer to one being more commonly reached. However, a common high maximum for quite a few relatively small numbers was a bit surprising.
1073741824 has 30 steps. (2^x has x steps)


I guess it makes sense the the ones that take many steps would end up on along similar numbers as the many shorter paths take up most the other numbers.
A new version of this scenario was uploaded on 2018-04-13 13:16:01 UTC Cleaned up code and added what I believe documentation is
A new version of this scenario was uploaded on 2018-04-13 23:48:47 UTC html 5 compatibility since i made the previous changes on an outdates greenfoot version
A new version of this scenario was uploaded on 2018-04-13 23:52:23 UTC what good is documentation of the sourse isnt availible?
A new version of this scenario was uploaded on 2019-01-21 03:16:32 UTC prints steps live.

See all comments

Want to leave a comment? You must first log in.

Who likes this?