fork download
  1. import java.util.function.*;
  2.  
  3. class Ideone {
  4. static Predicate<String> isPalindrome =
  5. s->s.matches("|(?:(.)(?<=(?=^.*?(\\1\\2?)$).*))+(?<=(?=^\\2$).*)")//)")*.)$2\\^=?(=<?(+))*.)$)?2\\1\\(?*.^=?(=<?().(:?(|"(sehctam.s>-s
  6. ;
  7.  
  8. public static void main (String[] args) throws java.lang.Exception {
  9. testPalindrome("", true);
  10. testPalindrome("x", true);
  11. testPalindrome("xx", true);
  12. testPalindrome("xy", false);
  13. testPalindrome("xyx", true);
  14. testPalindrome("xxx", true);
  15. testPalindrome("xxyx", false);
  16. testPalindrome("racecar", true);
  17. testPalindrome("step on no pets", true);
  18. testPalindrome("aManaPlanaCanalPanaMa", true);
  19. testPalindrome("this is impossible", false);
  20. }
  21.  
  22. static void testPalindrome(String s, boolean expected) {
  23. if (isPalindrome.test(s) == expected) {
  24. System.out.println("OK");
  25. } else {
  26. System.out.printf("NOK: str=\"%s\", expected=%b%n", s, expected);
  27. }
  28. }
  29. }
Success #stdin #stdout 0.08s 711680KB
stdin
Standard input is empty
stdout
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK