int main(){ int i; /* run i number of test candidates */ for(i=1; i<47; i++){ isLychrel(i); } printf("Total Lychrel numbers: %lu\n", lychrel); return 0; }
int isLychrel(short int depth, long int number) { if(depth > CUTOFF_DEPTH) { return 1; } long int newNumber = number + reverseDigits(number); return isPalindrome(newNumber) ? 0 : isLychrel(++depth, newNumber); }
int main (int argc, const char * argv[]) { printf("Problem 55 - Checking for Lychrel numbers!\n"); int lychrelCount = 0; int num = 1; for(num = 1; num < 10000; ++num) { lychrelCount += isLychrel(0, num) ? 1 : 0; } printf("Lychrel number count: %d\n", lychrelCount); return 0; }
/* * Loop over integers 1 to 9999. Pass cursor [i] to * function [isLychrel]. If [i] is a Lychrel number, * increment counter [c]. When done, output [c]. */ void problem0055::run() { int c = 0; for (int i = 1; i <= 9999; ++i) c += isLychrel(i); std::cout << c; }