Post History
Background Check out this video on the Collatz conjecture, also known as A006577. If you don't know what this is, we're given an equation of $3x + 1$, and it is applied this way: If $x$ is odd...
#3: Post edited
Collatz conjecture; Count the tries to reach $1$
- # Background
Check out [this video on the Collatz conjecture](https://www.youtube.com/watch?v=094y1Z2wpJg), also known as A006577[^1].- If you don't know what this is, we're given an equation of $3x + 1$, and it is applied this way:
- - If $x$ is odd, then $3x + 1$.
- - If $x$ is even, then $\frac{x}{2}$.
- This will send us in a loop of `4 → 2 → 1 → 4 → 2 → 1...`, which got me into making this challenge.
- # Challenge
- Write a program that establishes the Collatz conjecture:
- - Take input of a positive integer. This will be the $x$ of the problem.
- - Read the background for how it works, or watch the video for further explanation.
- - The result should be how many turns it would take before reaching $1$. There, the sequence stops.
- - This is <a class="badge is-tag">code-golf</a>, so the shortest program in each language wins!
- # Test Cases
- From 1 to 10:
- ```
- 1 → 0 (1)
- 2 → 1 (2 → 1)
- 3 → 7 (3 → 10 → 5 → 16 → 8 → 4 → 2 → 1)
- 4 → 2 (4 → 2 → 1)
- 5 → 5 (5 → 16 → 8 → 4 → 2 → 1)
- 6 → 8 (6 → 3 → 10 → 5 → 16 → 8 → 4 → 2 → 1)
- 7 → 16 (7 → 22 → 11 → 34 → 17 → 52 → 26 → 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1)
- 8 → 3 (8 → 4 → 2 → 1)
- 9 → 19 (9 → 28 → 14 → 7 → 22 → 11 → 34 → 17 → 52 → 26 → 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1)
- 10 → 6 (10 → 5 → 16 → 8 → 4 → 2 → 1)
- ```
More of these can be found on OEIS (see reference 1). Thanks to [**@Shaggy**](https://codegolf.codidact.com/users/53588) for the link![^1]: https://oeis.org/A006577
- # Background
- Check out [this video on the Collatz conjecture](https://www.youtube.com/watch?v=094y1Z2wpJg), also known as [A006577][1].
- If you don't know what this is, we're given an equation of $3x + 1$, and it is applied this way:
- - If $x$ is odd, then $3x + 1$.
- - If $x$ is even, then $\frac{x}{2}$.
- This will send us in a loop of `4 → 2 → 1 → 4 → 2 → 1...`, which got me into making this challenge.
- # Challenge
- Write a program that establishes the Collatz conjecture:
- - Take input of a positive integer. This will be the $x$ of the problem.
- - Read the background for how it works, or watch the video for further explanation.
- - The result should be how many turns it would take before reaching $1$. There, the sequence stops.
- - This is <a class="badge is-tag">code-golf</a>, so the shortest program in each language wins!
- # Test Cases
- From 1 to 10:
- ```
- 1 → 0 (1)
- 2 → 1 (2 → 1)
- 3 → 7 (3 → 10 → 5 → 16 → 8 → 4 → 2 → 1)
- 4 → 2 (4 → 2 → 1)
- 5 → 5 (5 → 16 → 8 → 4 → 2 → 1)
- 6 → 8 (6 → 3 → 10 → 5 → 16 → 8 → 4 → 2 → 1)
- 7 → 16 (7 → 22 → 11 → 34 → 17 → 52 → 26 → 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1)
- 8 → 3 (8 → 4 → 2 → 1)
- 9 → 19 (9 → 28 → 14 → 7 → 22 → 11 → 34 → 17 → 52 → 26 → 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1)
- 10 → 6 (10 → 5 → 16 → 8 → 4 → 2 → 1)
- ```
- More of these can be found [on OEIS][1]. Thanks to [**@Shaggy**](https://codegolf.codidact.com/users/53588) for the link!
- [1]: https://oeis.org/A006577
#2: Post edited
> This challenge is currently under beta release. If given enough positivity, it will remain here and stand as a fully released challenge. Otherwise, it will be deleted and put back in the [sandboxed post](https://codegolf.codidact.com/posts/284040/). Please fix the errors there instead.- # Background
- Check out [this video on the Collatz conjecture](https://www.youtube.com/watch?v=094y1Z2wpJg), also known as A006577[^1].
- If you don't know what this is, we're given an equation of $3x + 1$, and it is applied this way:
- - If $x$ is odd, then $3x + 1$.
- - If $x$ is even, then $\frac{x}{2}$.
- This will send us in a loop of `4 → 2 → 1 → 4 → 2 → 1...`, which got me into making this challenge.
- # Challenge
- Write a program that establishes the Collatz conjecture:
- - Take input of a positive integer. This will be the $x$ of the problem.
- - Read the background for how it works, or watch the video for further explanation.
- - The result should be how many turns it would take before reaching $1$. There, the sequence stops.
- - This is <a class="badge is-tag">code-golf</a>, so the shortest program in each language wins!
- # Test Cases
- From 1 to 10:
- ```
- 1 → 0 (1)
- 2 → 1 (2 → 1)
- 3 → 7 (3 → 10 → 5 → 16 → 8 → 4 → 2 → 1)
- 4 → 2 (4 → 2 → 1)
- 5 → 5 (5 → 16 → 8 → 4 → 2 → 1)
- 6 → 8 (6 → 3 → 10 → 5 → 16 → 8 → 4 → 2 → 1)
- 7 → 16 (7 → 22 → 11 → 34 → 17 → 52 → 26 → 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1)
- 8 → 3 (8 → 4 → 2 → 1)
- 9 → 19 (9 → 28 → 14 → 7 → 22 → 11 → 34 → 17 → 52 → 26 → 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1)
- 10 → 6 (10 → 5 → 16 → 8 → 4 → 2 → 1)
- ```
- More of these can be found on OEIS (see reference 1). Thanks to [**@Shaggy**](https://codegolf.codidact.com/users/53588) for the link!
- [^1]: https://oeis.org/A006577
- # Background
- Check out [this video on the Collatz conjecture](https://www.youtube.com/watch?v=094y1Z2wpJg), also known as A006577[^1].
- If you don't know what this is, we're given an equation of $3x + 1$, and it is applied this way:
- - If $x$ is odd, then $3x + 1$.
- - If $x$ is even, then $\frac{x}{2}$.
- This will send us in a loop of `4 → 2 → 1 → 4 → 2 → 1...`, which got me into making this challenge.
- # Challenge
- Write a program that establishes the Collatz conjecture:
- - Take input of a positive integer. This will be the $x$ of the problem.
- - Read the background for how it works, or watch the video for further explanation.
- - The result should be how many turns it would take before reaching $1$. There, the sequence stops.
- - This is <a class="badge is-tag">code-golf</a>, so the shortest program in each language wins!
- # Test Cases
- From 1 to 10:
- ```
- 1 → 0 (1)
- 2 → 1 (2 → 1)
- 3 → 7 (3 → 10 → 5 → 16 → 8 → 4 → 2 → 1)
- 4 → 2 (4 → 2 → 1)
- 5 → 5 (5 → 16 → 8 → 4 → 2 → 1)
- 6 → 8 (6 → 3 → 10 → 5 → 16 → 8 → 4 → 2 → 1)
- 7 → 16 (7 → 22 → 11 → 34 → 17 → 52 → 26 → 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1)
- 8 → 3 (8 → 4 → 2 → 1)
- 9 → 19 (9 → 28 → 14 → 7 → 22 → 11 → 34 → 17 → 52 → 26 → 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1)
- 10 → 6 (10 → 5 → 16 → 8 → 4 → 2 → 1)
- ```
- More of these can be found on OEIS (see reference 1). Thanks to [**@Shaggy**](https://codegolf.codidact.com/users/53588) for the link!
- [^1]: https://oeis.org/A006577
#1: Initial revision
Collatz conjecture; Count the tries to reach $1$
> This challenge is currently under beta release. If given enough positivity, it will remain here and stand as a fully released challenge. Otherwise, it will be deleted and put back in the [sandboxed post](https://codegolf.codidact.com/posts/284040/). Please fix the errors there instead. # Background Check out [this video on the Collatz conjecture](https://www.youtube.com/watch?v=094y1Z2wpJg), also known as A006577[^1]. If you don't know what this is, we're given an equation of $3x + 1$, and it is applied this way: - If $x$ is odd, then $3x + 1$. - If $x$ is even, then $\frac{x}{2}$. This will send us in a loop of `4 → 2 → 1 → 4 → 2 → 1...`, which got me into making this challenge. # Challenge Write a program that establishes the Collatz conjecture: - Take input of a positive integer. This will be the $x$ of the problem. - Read the background for how it works, or watch the video for further explanation. - The result should be how many turns it would take before reaching $1$. There, the sequence stops. - This is <a class="badge is-tag">code-golf</a>, so the shortest program in each language wins! # Test Cases From 1 to 10: ``` 1 → 0 (1) 2 → 1 (2 → 1) 3 → 7 (3 → 10 → 5 → 16 → 8 → 4 → 2 → 1) 4 → 2 (4 → 2 → 1) 5 → 5 (5 → 16 → 8 → 4 → 2 → 1) 6 → 8 (6 → 3 → 10 → 5 → 16 → 8 → 4 → 2 → 1) 7 → 16 (7 → 22 → 11 → 34 → 17 → 52 → 26 → 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1) 8 → 3 (8 → 4 → 2 → 1) 9 → 19 (9 → 28 → 14 → 7 → 22 → 11 → 34 → 17 → 52 → 26 → 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1) 10 → 6 (10 → 5 → 16 → 8 → 4 → 2 → 1) ``` More of these can be found on OEIS (see reference 1). Thanks to [**@Shaggy**](https://codegolf.codidact.com/users/53588) for the link! [^1]: https://oeis.org/A006577