Skip to content

Instantly share code, notes, and snippets.

@Rhomboid
Created November 2, 2012 00:43
Show Gist options
  • Save Rhomboid/3997891 to your computer and use it in GitHub Desktop.
Save Rhomboid/3997891 to your computer and use it in GitHub Desktop.
project euler #4
#include <iostream>
static bool is_palendrome(int n)
{
if(n >= 100000)
return n / 100000 % 10 == n % 10 &&
n / 10000 % 10 == n / 10 % 10 &&
n / 1000 % 10 == n / 100 % 10;
else if(n >= 10000)
return n / 10000 % 10 == n % 10 &&
n / 1000 % 10 == n / 10 % 10;
return false;
}
int main()
{
int largest = 0;
for(int a = 100; a < 1000; a++) {
for(int b = 100; b < 1000; b++) {
int val = a * b;
if(is_palendrome(val) && val > largest)
largest = val;
}
}
std::cout << largest << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment