Created
November 25, 2013 01:54
-
-
Save Kojirion/7635069 to your computer and use it in GitHub Desktop.
Project Euler problem 55
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <boost/timer/timer.hpp> | |
#include <boost/range/irange.hpp> | |
#include <boost/range/algorithm/count_if.hpp> | |
#include <algorithm> | |
#include <gmpxx.h> | |
using boost::irange; | |
typedef mpz_class Int; | |
Int reverse(Int n){ | |
auto string = n.get_str(); | |
std::reverse(string.begin(), string.end()); | |
return Int(string, 10); | |
} | |
bool isPalindrome(Int n){ | |
return n == reverse(n); | |
} | |
bool isLychrel(Int n){ | |
for (auto i : irange(0, 50)){ | |
n = n + reverse(n); | |
if (isPalindrome(n)) return false; | |
} | |
return true; | |
} | |
int main() | |
{ | |
boost::timer::auto_cpu_timer t; | |
std::cout << boost::count_if(irange(0, 10000), isLychrel) << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment