Collatz Conjecture

Java Programming Course


Course 1: Problem-Solving and Computational Thinking in Java

Sprint 5: Working with Looping Constructs


Problem Statement

Calculate the number of steps required to reach 1 from a given number n by following the Collatz sequence.

$$f(n) = \begin{cases}\frac{3n+1}{2}&\text{ if $n$ is odd,}\\\frac{n}{2}&\text{ if $n$ is even.}\end{cases}$$

Task

  1. Open the source code file and complete the code.
  2. Open the test case file and run the test cases to check your code.

Fun Resources

  1. List of number of steps to reach 1 for Collatz Conjecture from OEIS
  2. Collatz Conjecture on OEIS (One-Line Encyclopedia for Integer Sequences)
  3. Collatz Conjecture on Wikipedia
  4. UNCRACKABLE? The Collatz Conjecture - Numberphile
  5. Collatz Conjecture in Color - Numberphile
  6. Conjecture meaning in the Cambridge English Dictionary
  7. What is the Collatz Conjecture? - CollatzResearch.org