The Collatz conjecture:wiki
Start with any positive integer n. Then each term is obtained from the previous term as follows:
- if the previous term is even, the next term is one half the previous term ( n / 2)
- if the previous term is odd, the next term is 3 times the previous term plus 1 ( 3n + 1 )
Numbers form a tree as they work their way down to 1, as seen in the image below. For example, starting with the number 5 you next get 16 ( 3x5 + 1 ) and then 8 ( 16 / 2 ). Starting with the number 64, you get 32 ( 64 / 2 ) and then 32. So the numbers 5 and 64 converge at 16.
Given an array of 2 numbers, return the number where the branches converge.
Sample input: [24, 26]
Answer: 10
Sample input [28, 29, 30]
Answer: 40