Collatz (3n+1) sequence in Java

Collatz (3n+1) sequence in java problem You wish to write some code to generate the well known Collatz sequence. More specific, given a number n, calculate and show the numbers from n concluding to 1. Recall the Collatz sequence always diverges to 1. SOLUTION Let’s revisit the mathematical formula:  In plain English, if the number […]

Collatz (3n + 1) sequence in JavaScript

Collatz (3n + 1) sequence in JavaScript problem You wish to generate the Collatz sequence using JavaScript. In this post we will see how to accomplish that and print in the console of the web browser that is in the web developer tools of each popular web browser. Recall the Collatz sequence starts by giving […]

Collatz sequence in C++

Calculate Collatz (3n + 1) sequence in C++ problem You wish to print the infamous Collatz sequence also known as 3n + 1. Given a natural number greater than 0, if it’s odd you multiply by 3 and add 1, otherwise you divide it by 2 and repeat this process until it becomes 1. Fun […]