Skip to content

Instantly share code, notes, and snippets.

@LuxXx
Created April 17, 2017 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LuxXx/e8952c697aae6e22f81b5f53a45a9627 to your computer and use it in GitHub Desktop.
Save LuxXx/e8952c697aae6e22f81b5f53a45a9627 to your computer and use it in GitHub Desktop.
Project Euler - Problem 36
package euler;
public class BasePalindrome {
public static void main(String[] args) {
int sum = 0;
for (int i = 0; i < 1_000_000; i++) {
if (isPalindrome(Integer.valueOf(i).toString()) && isPalindrome(Integer.toBinaryString(i))) {
sum += i;
}
}
System.out.println(sum);
}
public static boolean isPalindrome(String s) {
for (int i = 0; i < s.length() / 2; i++) {
if (s.charAt(i) != s.charAt(s.length() - i - 1)) return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment