spark: add palindrome checker utility
This commit is contained in:
1 parent
aec5988f87
commit
dfa0869042
1 file changed
+16
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Palindrome checker - returns 0 if palindrome, 1 otherwise."""
|
||||
import sys
|
||||
|
||||
def is_palindrome(s: str) -> bool:
|
||||
"""Check if string is palindrome (ignoring case, non-alphanumeric)."""
|
||||
cleaned = ''.join(c.lower() for c in s if c.isalnum())
|
||||
return cleaned == cleaned[::-1]
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python3 palindrome.py <string>")
|
||||
sys.exit(2)
|
||||
result = is_palindrome(sys.argv[1])
|
||||
print(f"{sys.argv[1]!r} is {'a palindrome' if result else 'not a palindrome'}")
|
||||
sys.exit(0 if result else 1)
|
||||
Reference in new issue
Block a user