Skip to content

Instantly share code, notes, and snippets.

@byyam
Created October 24, 2019 14:38
Show Gist options
  • Save byyam/0e20d7cf28d0162f9e47e660abd73bd0 to your computer and use it in GitHub Desktop.
Save byyam/0e20d7cf28d0162f9e47e660abd73bd0 to your computer and use it in GitHub Desktop.
collatz conjecture
#include <stdio.h>
#include <limits.h>
const int s = 30;
bool f(long i)
{
int r = 0;
for(;;)
if (i < 0 || r > s) return false;
else if (i == 1) break;
else{r ++;i = i % 2 ? 3*i + 1 : i/2;}
return (r==s);
}
int main(){
for(long i = 1; i < LONG_MAX; i++) if (f(i)) printf("%ld ", i);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment