/algorithm-night-collatz

Toy problem for CodeWorks algorithm night.

Primary LanguageJavaScriptGNU General Public License v3.0GPL-3.0

The Collatz Sequence

Instructions

Create a function which computes the Collatz Conjecture sequence for a positive integer n. The sequence is calculated as follows:

  • If n is even, the next number in the sequence is n / 2
  • If n is odd, the next number in the sequence is 3 * n + 1
  • If n is 1, we have reached the end of the sequence (notice that once we reach 1, the sequence will end up in a loop of 1 => 4 => 2 => 1)

Now, create a second function which finds the number n with the longest Collatz sequence between 1 and positive integer i. If two numbers have the same sequence length, return the smaller of the two numbers.

  1. Fork this respository
  2. Clone it
  3. Solve it
  4. Submit pull request

Read More

To read more about the Collatz Conjecture, see the links below: https://en.wikipedia.org/wiki/Collatz_conjecture https://www.youtube.com/watch?v=5mFpVDpKX70&feature=share