Skip to content

Instantly share code, notes, and snippets.

@lilyball
Created November 8, 2011 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lilyball/1348790 to your computer and use it in GitHub Desktop.
Save lilyball/1348790 to your computer and use it in GitHub Desktop.
ix's C solution for Project Euler #14
#include <stdio.h>
int main(int argc, char **argv)
{
int longest = 0;
int terms = 0;
int i;
unsigned long j;
for (i = 1; i <= 1000000; i++)
{
j = i;
int this_terms = 1;
while (j != 1)
{
this_terms++;
if (this_terms > terms)
{
terms = this_terms;
longest = i;
}
if (j % 2 == 0)
{
j = j / 2;
}
else
{
j = 3 * j + 1;
}
}
}
printf("longest: %d (%d)\n", longest, terms);
return 0;
}
@lilyball
Copy link
Author

lilyball commented Nov 8, 2011

This solution was copied from the thread for Project Euler problem #14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment