From 214100fb7293eb847b985ff354d139fcd77c9830 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Sun, 3 Dec 2017 03:28:08 +0100 Subject: [PATCH] Simplify and add list of all lychrel numbers under 10000 --- lychrel.cpp | 2 +- lychrel.txt | 241 ++++++++++++++++++++++++++++++++++++++++++++++++++++ main.cpp | 24 ++---- 3 files changed, 251 insertions(+), 16 deletions(-) create mode 100644 lychrel.txt diff --git a/lychrel.cpp b/lychrel.cpp index 5fd57bb..8029ede 100644 --- a/lychrel.cpp +++ b/lychrel.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include "lychrel.hpp" long long get_len (string a, string b) { diff --git a/lychrel.txt b/lychrel.txt new file mode 100644 index 0000000..9df559a --- /dev/null +++ b/lychrel.txt @@ -0,0 +1,241 @@ +196 +295 +394 +493 +592 +689 +691 +788 +790 +879 +887 +978 +986 +1495 +1497 +1585 +1587 +1675 +1677 +1765 +1767 +1855 +1857 +1945 +1947 +1997 +2494 +2496 +2584 +2586 +2674 +2676 +2764 +2766 +2854 +2856 +2944 +2946 +2996 +3493 +3495 +3583 +3585 +3673 +3675 +3763 +3765 +3853 +3855 +3995 +4079 +4169 +4259 +4349 +4439 +4492 +4494 +4529 +4582 +4584 +4619 +4672 +4674 +4709 +4799 +4762 +4764 +4852 +4854 +4889 +4899 +4942 +4944 +4979 +4994 +5078 +5168 +5258 +5348 +5438 +5491 +5528 +5581 +5583 +5618 +5671 +5673 +5708 +5761 +5763 +5798 +5851 +5853 +5888 +5941 +5943 +5978 +5993 +6077 +6167 +6257 +6347 +6437 +6517 +6607 +6670 +6672 +6707 +6760 +6762 +6797 +6850 +6852 +6940 +6942 +6977 +6992 +7057 +7076 +7059 +7149 +7166 +7239 +7256 +7329 +7346 +7419 +7436 +7491 +7509 +7526 +7581 +7599 +7616 +7671 +7706 +7761 +7779 +7796 +7851 +7886 +7869 +7941 +7951 +7959 +7976 +7991 +8058 +8075 +8079 +8089 +8148 +8165 +8169 +8179 +8238 +8255 +8259 +8269 +8328 +8345 +8349 +8359 +8418 +8435 +8439 +8449 +8490 +8508 +8525 +8529 +8539 +8580 +8598 +8615 +8619 +8629 +8670 +8688 +8705 +8709 +8719 +8760 +8778 +8809 +8850 +8868 +8885 +8889 +8899 +8940 +8958 +8975 +8979 +8989 +8990 +9057 +9074 +9078 +9088 +9147 +9164 +9168 +9178 +9237 +9254 +9258 +9268 +9327 +9344 +9348 +9358 +9417 +9434 +9438 +9448 +9507 +9524 +9528 +9538 +9597 +9614 +9618 +9628 +9687 +9704 +9708 +9718 +9777 +9794 +9798 +9808 +9867 +9884 +9888 +9898 +9957 +9974 +9978 +9988 +9999 diff --git a/main.cpp b/main.cpp index c5e6f88..4e1a17c 100644 --- a/main.cpp +++ b/main.cpp @@ -7,25 +7,19 @@ int main(int argc, char **argv) { string a = argv[1]; - string b(a.rbegin(),a.rend()); - string added = add(a,b); - if(added == "-1") { - 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; - } + cout << "Starting with " << a; + string added = a; long long it = 0; do { - cout << "Iteration " << ++it << " currently working on " << added << endl; - a = added; - b = string(a.rbegin(),a.rend()); + a = added; + string b = string(a.rbegin(),a.rend()); added = add(a,b); - if(added == "-1") { + if(added == "-1") { 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; + return 1; } - } while(! is_palindrome(added)); - cout << "Iteration " << ++it << " currently working on " << added << endl; - cout << "That consists of\n" << a << "\n+\n" << b << "\nand that it " << (is_palindrome(added) ? "is" : "is not") << " a palindrome." << endl; - + it++; + } while(! is_palindrome(added)); + cout << " " << added << " is a palindrome and was found after " << it << " iterations.\n"; return 0; }