Skip to content

Instantly share code, notes, and snippets.

@circuitsenses
Last active February 13, 2016 08:56
Show Gist options
  • Save circuitsenses/cac88d484cf4618961fe to your computer and use it in GitHub Desktop.
Save circuitsenses/cac88d484cf4618961fe to your computer and use it in GitHub Desktop.
Collatz Conjecture on Intel Machines
#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