Last active
February 13, 2016 08:56
-
-
Save circuitsenses/cac88d484cf4618961fe to your computer and use it in GitHub Desktop.
Collatz Conjecture on Intel Machines
This file contains 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
#include <stdio.h> | |
int main() | |
{ | |
unsigned long long n = 1; | |
unsigned long long saved_n = n; | |
unsigned long long curr_seq_len = 1; | |
unsigned long long prev_seq_len = 0; | |
for (;;) | |
{ | |
saved_n = n; | |
do { | |
if (!(n & 1)) | |
{ | |
n = n >> 1; | |
} | |
else | |
{ | |
n = (n << 1) + (n + 1); | |
} | |
curr_seq_len++; | |
} while (n != 1); | |
if (curr_seq_len > prev_seq_len) | |
{ | |
printf("N: %lld, S: %lld\n", saved_n, curr_seq_len); | |
prev_seq_len = curr_seq_len; | |
} | |
curr_seq_len = 1; | |
n = saved_n; | |
n++; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment