Last active
February 2, 2024 03:11
-
-
Save plasmarad/12b8e3cd9045e950fc4809f6073833cb to your computer and use it in GitHub Desktop.
Collatz conjecture is an arithmetic problem in which there are 2 rules, If a inputted number is even: divide by 2. if the inputted number is odd: multiply by 3 and add 1, whats interesting about this conjecture is that it will always result in a loop resulting in 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
plasmarad - 2024 | |
CollatzConjecture: | |
if a number is even: divide by 2 | |
if a number is odd : Mult 3 add 1 | |
Eventually, with all numbers, it will loop into 1 [ex: 1 -> 4 -> 2 -> 1] | |
*/ | |
#include <stdint.h> | |
#include <iostream> | |
uint64_t _3xP1(uint64_t Number){ | |
if (Number % 2 == 0) return Number / 2 ; | |
else return 3 * Number + 1; | |
} | |
int main (){ | |
uint64_t seed = 18446744073709551615; | |
std::cin >> seed; | |
while (seed != 1) { | |
seed = _3xP1 (seed); | |
std::cout << seed << std::endl; | |
} | |
} | |
// plasmarad - 2024 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Refactor, condensed, and simplified code.
not to forget the better comment explanation.