The Collatz function

Rule

Each term is: If even divide by two or if odd multiply by three and add one

Known as: The Collatz function

  • If the number is even, divide it by two.
  • If the number is odd, multiply it by three and add one.

The unsolved Collatz conjecture is that repeating this process from any number will eventually reach the number 1.

The first 50 terms (starting from n=1) are:

4 1 10 2 16 3 22 4 28 5 34 6 40 7 46 8 52 9 58 10 64 11 70 12 76 13 82 14 88 15 94 16 100 17 106 18 112 19 118 20 124 21 130 22 136 23 142 24 148 25

Example

To get the value for n=13:

  • This is odd, so multiply by three and add one giving 40.

So the result is 40.

References

On-Line Encyclopedia of Integer Sequences