https://github.com/pedrokehl/collatz
Algorithm to calculate the Collatz sequence (Zero dependencies)
https://github.com/pedrokehl/collatz
collatz javascript
Last synced: about 1 year ago
JSON representation
Algorithm to calculate the Collatz sequence (Zero dependencies)
- Host: GitHub
- URL: https://github.com/pedrokehl/collatz
- Owner: pedrokehl
- Created: 2020-03-19T21:22:07.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-19T21:33:57.000Z (about 6 years ago)
- Last Synced: 2025-02-13T09:53:28.277Z (over 1 year ago)
- Topics: collatz, javascript
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Collatz Sequence Algorithm
This repository ships an implementation for the following question:
**Which starting number, under one million, produces the longest chain on the Collatz Sequence?**
Collatz:
- The iterative sequence is defined for the set of positive integers
- Given a number n in the Collatz sequence,
- if n is even, the next number in the sequence is n/2
- if n is odd, the next number in the sequence is 3n + 1
- Applying the rule above with the starting number 13, we generate the following sequence:
- 13 40 20 10 5 16 8 4 2 1 It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms.