lychrel/main.cpp

26 lines
691 B
C++
Raw Normal View History

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];
cout << "Starting with " << a;
string added = a;
2017-12-02 16:55:48 +01:00
long long it = 0;
do {
a = added;
string b = string(a.rbegin(),a.rend());
2017-12-02 16:55:48 +01:00
added = add(a,b);
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";
return 1;
2017-12-02 17:39:03 +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;
}