Collatz function

by Ricardo Fernández Serrata

Version 2 (May 17, 2021)

Download (17 downloads)

Returns the (Hailstone) sequence of a number that has passed through the Collatz Algorithm. This supports negative numbers and the use of the "shortcut version".

You can explicitly specify the iterations you want to apply to the number by using k. If k is falsy, the flow will halt when a known cycle is detected.

This uses {x % 2} instead of {x & 1} because bitwise operations don't work correctly on numbers larger than 31 bits. This doesn't happen in Javascript, JS performs wrap-around instead of AM's clamping.

ℹ en.wikipedia.org/wiki/Collatz_conjecture

4.0 average rating from 1 reviews

5 stars
0
4 stars
1
3 stars
0
2 stars
0
1 star
0
Reports
0

Rate and review within the app in the Community section.