Skip to content

A simple command line visualizer of the Collatz Conjecture.

Notifications You must be signed in to change notification settings

Caisesiume/Collatz-Conjecture-Logs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Collatz-Conjecture (3n+1)

This Collatz-Conjecture (3n+1) algorithm prints each calculated sequence in a given interval of integers.


The Collatz-Conjecture is a conjecture in mathematics that concerns a sequence defined as follows:

  1. Start with any positive integer n.
  2. Then each term is obtained from the previous term. If the previous term is even, the next term is half of the previous term. If the previous term is odd, the next term is x3 the previous term, plus 1.
The Collatz-Conjecture Expression

The conjecture is that no matter what value of n, the sequence will always reach 1 at some point.

What does this program do?

For each number tested in the interval

  • Lists all the visited numbers in order (e.g 5, 16, 8, 4, 2, 1),

Output post calculation

  • Largest integer reached

  • What iteration had the largest integer

  • The longest sequence

  • Total count of nodes (numbers) visited

  • Number of sequences calculated

Different languages

Python

Preferably executed with python3, python 3NPlus1.py in terminal.

In 3NPlus1.py the max number to calculate is defined on line 29.

Default max value: 50

26 ...
27 
28 def main():
29      upper_limit = 50
30
31 ...

Node.js

Preferably executed in terminal using node 3NPlus1.js .

In 3NPlus1.js the interval of numbers to calculate is defined on line 5.

Default max value: 50

3 ...
4 */
5 const stats = await startCount(1,50);
6
7 ...

C/C++

Preferably executed with gcc, gcc 3NPlus1.c. Then run the executable in the terminal.

In 3NPlus1.c the max number to calculate is defined on line 33.

Default max value: 50

30 ...
31
32 int main() {
33      int upperLimit = 50;   
34      ...

About

A simple command line visualizer of the Collatz Conjecture.

Topics

Resources

Stars

Watchers

Forks