Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tonybaines/7e8dcb37357bf61e0109913efff4eb5d to your computer and use it in GitHub Desktop.
Save tonybaines/7e8dcb37357bf61e0109913efff4eb5d to your computer and use it in GitHub Desktop.
import java.util.stream.IntStream;
class Scratch {
public static void main(String[] args) {
int lowerBound = 100;
int upperBound = 999;
System.out.println(
IntStream.range(lowerBound, upperBound).flatMap(x ->
IntStream.range(lowerBound, upperBound).map(y -> x * y)
.filter(Scratch::isPalindrome)
).max().getAsInt());
}
private static boolean isPalindrome(int i) {
String forward = Integer.toString(i);
String reverse = new StringBuilder(Integer.toString(i)).reverse().toString(); // yuk
return forward.equals(reverse);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment