2017-12-02 16:55:48 +01:00
|
|
|
#include <iostream>
|
|
|
|
#include <cstring>
|
2017-12-02 17:39:03 +01:00
|
|
|
#include <climits>
|
2017-12-02 16:55:48 +01:00
|
|
|
#include "lychrel.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
string a = argv[1];
|
2017-12-03 03:28:08 +01:00
|
|
|
cout << "Starting with " << a;
|
|
|
|
string added = a;
|
2017-12-02 16:55:48 +01:00
|
|
|
long long it = 0;
|
|
|
|
do {
|
2017-12-03 03:28:08 +01:00
|
|
|
a = added;
|
|
|
|
string b = string(a.rbegin(),a.rend());
|
2017-12-02 16:55:48 +01:00
|
|
|
added = add(a,b);
|
2017-12-03 03:28:08 +01:00
|
|
|
if(added == "-1") {
|
2017-12-02 17:39:03 +01:00
|
|
|
cerr << "ERROR: adding error detected, we might have reached the end of our datatype or some how the two numbers don't have the same legth\n";
|
2017-12-03 03:28:08 +01:00
|
|
|
return 1;
|
2017-12-02 17:39:03 +01:00
|
|
|
}
|
2017-12-03 03:28:08 +01:00
|
|
|
it++;
|
|
|
|
} while(! is_palindrome(added));
|
|
|
|
cout << " " << added << " is a palindrome and was found after " << it << " iterations.\n";
|
2017-12-02 16:55:48 +01:00
|
|
|
return 0;
|
|
|
|
}
|