The Collatz Conjecture

What is this?

The Collatz Conjecture is an unsolved problem in mathematics which asks if repeating two simple arithmetic operations will eventually transform any positive integer to 1.

The reason this is an unsolved problem is because no proof has yet been produced for whether or not this works for any positive integer.

The Process

  1. Receive some input. This can be any positive integer.
    1. If the input is odd multiply it by 3 then add 1.
    2. If the input is even divide it by 2.
  2. Repeat.
example 1

Input: 10

10 ÷ 2 = 5
(5 × 3) + 1 = 16
16 ÷ 2 = 8
8 ÷ 2 = 4
4 ÷ 2 = 2
2 ÷ 2 = 1
(1 × 3) + 1 = 4
4 ÷ 2 = 2
2 ÷ 2 = 1

As you can see, once the result hits 1 the steps will enter into a loop that repeats forever.

Observations

Since the process is so simple I haven't noticed too many things that yield unusual results. Probably the closest thing to "quirky" that I've observed is if the intput is some power of 2 you will get that many "divide by 2" operations until you reach 1. That's fairly obvious as the opposite of "divide by 2" is "multiply by 2" and it's not too drastic a leap to get to 2y. In the following example, let's input 2⁸ (256).

example 2

Input: 256

256 ÷ 2 = 128
128 ÷ 2 = 64
64 ÷ 2 = 32
32 ÷ 2 = 16
16 ÷ 2 = 8
8 ÷ 2 = 4
4 ÷ 2 = 2
2 ÷ 2 = 1

I am not a math professional, or even an amateur for that matter, so I have no idea how to go about finding anything truly interesting or odd. Maybe you'll have more luck in that regard.

Try it out.

Please note: Due to limitations with how JavaScript handles integers, I have set this up to limit the input to a maximum of 15 digits. If you want to try this out for yourself without such limits, clone this repository, remove or increase the limits, and upload it to your own server.

Please enter a number with fewer than 15 digits.

Results

Input:

Unique digits: