without memoization this solution for Euler Project 14 works fine! Then with memoization it should work faster... but it stops nearly at i = 1818 or near. How strange! what's wrong trying hard to understand! can you help?
#include <stdio.h>
#define limit 1000000
int arr[limit];
int fun(long long int i) {
long long int count = 1;
long long int num;
arr[limit];
num = i;
while (num > 1) {
if (arr[num] != NULL) {
count = count - 1 + arr[num];
break;
}
if (num % 2 == 0) {
num = num / 2;
count++;
} else {
num = 3 * num + 1;
count++;
}
}
arr[i] = count;
return count;
}
int main() {
long long int i;
for (i = 2; i < limit; i++) {
long long int count = fun(i);
printf("d %lld c: %lld\n", i, count);
}
return 0;
}