
Hi Community members,
A solution to last week’s challenge can be found here.
This challenge for the mathematicians at heart was submitted by Ippei Nakagawa (@gawa). Thank you, Ippei, for this challenge!
The Collatz conjecture, also known as the 3n + 1 problem, is a conjecture in mathematics named after Lothar Collatz, who introduced it in 1937. It is an unsolved problem in mathematics that is simple to state but difficult to prove. The problem is defined as follows:
- Start with any positive integer N.
- Apply the following rules:
- If N is even, divide it by 2.
- If N is odd, multiply it by 3 and add 1.
- Repeat the process with the resulting number as much as necessary to reach the number 1. The conjecture states that no matter what positive integer N you start with, you will always eventually reach the number 1.
Here is an example:
Start with N=6:
- 6 is even, so 6/2=3
- 3 is odd, so 3×3+1=10
- 10 is even, so 10/2=5
- 5 is odd, so 5×3+1=16
- 16 is even, so 16/2=8
- 8 is even, so 8/2=4
- 4 is even, so 4/2=2
- 2 is even, so 2/2=1
A total of 8 steps were required in this example.
For this challenge, you need to create an iterative macro that simulates the repeated steps until reaching 1 for each number. Once the macro is created, your tasks are to:
- Generate the numbers from 1 to 10,000.
- Use the iterative macro to apply the Collatz conjecture to each number.
- Identify the maximum number of steps used to reach the number 1.
Need a refresher? Review the following lessons in Academy to gear up:
Good luck!
The Academy Team