Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. List strings = ['civic', 'ivicc', 'civil', 'livci', 'ttaocca', 'aibohphobia', 'opp', 'abcdefghijklmnopqrstuvwxyz', 'totatot', 'totot', 'deleveled', 'aaab', 'aaabbb', 'noon']
  2.  
  3. def betterIsAnyPalindrome = { String str ->
  4. List chars = str.chars.toList()
  5. Integer s = chars.size()
  6. if( s % 2 == 0 ) {
  7. return chars.findAll { chars.count(it) % 2 == 0 }.size() == s
  8. }
  9. else {
  10. return [s, s-1].contains( chars.findAll { chars.count(it) % 2 == 0 || chars.count(it) % 3 == 0 }.size() )
  11. }
  12. }
  13.  
  14. strings.each {
  15. println it + ': ' + betterIsAnyPalindrome(it)
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement