Skip to content

Instantly share code, notes, and snippets.

@llelf
Created November 30, 2013 18:01
Show Gist options
  • Save llelf/7722337 to your computer and use it in GitHub Desktop.
Save llelf/7722337 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int result_c (int max_a0, int *max_len_r, int *longest_r) {
int longest = 0, max_len = 0;
int a0, len;
unsigned long a;
for (a0 = 1; a0 <= max_a0; a0++) {
a = a0;
len = 0;
while (a != 1) {
len++;
a = ((a%2==0)? a : 3*a+1)/2;
}
if (len > max_len) {
max_len = len;
longest = a0;
}
}
*max_len_r = max_len;
*longest_r = longest;
/* printf("(%d, %d)\n", max_len, longest); */
return longest;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment