Skip to content

Instantly share code, notes, and snippets.

@cdeszaq
Created July 8, 2013 21:25
Show Gist options
  • Save cdeszaq/5952644 to your computer and use it in GitHub Desktop.
Save cdeszaq/5952644 to your computer and use it in GitHub Desktop.
// isPalindrome - ignore cases, spaces and punctuation
// Empty string is false
// O(1) space, cant modify original string
[1,2,3,4,5,6].each {
println "Running isPalindrome${it}"
assert !"isPalindrome${it}"("") // False
assert !"isPalindrome${it}"(" !,! ") // False
assert "isPalindrome${it}"("M") // True
assert "isPalindrome${it}"("MM..M") // True
assert "isPalindrome${it}"("Madam! I'm... Adam!!!!!") // True
}
// Assume you have this method available
def isAlphaNumeric(c) {
c ==~ "[A-Za-z0-9]"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment