Skip to content

Instantly share code, notes, and snippets.

@Kojirion
Created November 25, 2013 01:54
Show Gist options
  • Save Kojirion/7635069 to your computer and use it in GitHub Desktop.
Save Kojirion/7635069 to your computer and use it in GitHub Desktop.
Project Euler problem 55
#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