42
11
A palindrome is some string that is spelled the same way both backwards and forwards. For instance, 'Eva, can I stab bats in a cave?' is a palindrome (EVACANISTAB | BATSINACAVE)
For this code golf, using the language of your choice, determine if a given string is a palindrome or not.
Edge Cases:
- Punctuation is not counted towards palindrominess.
- Control characters are not counted towards palindrominess.
- Whitespace is not counted towards palindrominess.
- Numbers are counted towards palindrominess.
- Case in this challenge is not counted towards palindrominess.
- There is no limit to the length of strings to evaluate, except for what is imposed by your language of choice.
- For this challenge, limit yourself to the ASCII character set.
Technical Requirements:
- Only method bodies are needed; additional things like method signatures, data structure declarations, etc. do not count towards the victory requirement.
- Code must compile or interpret without compile-time errors or exceptions.
- Code must not throw any unhandled exceptions or crash. (Almost needless to say. Almost.)
- Code must return some value indicating palindrominess. The data type depends on the language you use (e.g. a C# user might use a
bool
, whereas a JavaScript user could use avar
.) - You may not write your own interpreter that performs this task as a 'native' capability so you can 'golf' a near-winning score. (Hopefully needless to say.)
Victory Condition:
- The shortest code in characters wins.
Current Leader: tmartin (k, 25 characters)
...Want the magic green check mark by your answer? Beat this guy's answer!
1Is I/O a part of the challenge, or a function body will do? – John Dvorak – 2013-04-08T18:43:29.713
What about case? Non-ASCII and control characters? – Peter Taylor – 2013-04-08T18:52:11.590
@PeterTaylor based on the example, case should be ignored. I assume control characters are punctuation. – John Dvorak – 2013-04-08T18:53:32.353
Updated with clarifications per comments. – Andrew Gray – 2013-04-08T19:05:33.153
1The "breadcrumbs" for showing how the work is refined are available site-wide in all answers via revision history. There's no need to have a full history visible in the current version of the answer. – Peter Taylor – 2013-04-08T20:27:31.553
Could you clarify
Code must not throw any unhandled exceptions or crash.
please? Should there be no exceptions for any input or any valid input? – skeevey – 2013-04-08T20:56:59.063No exceptional states for any input; the edge case descriptions should ensure that the given code is immune to any gotchas (emphasis on should.) – Andrew Gray – 2013-04-08T21:00:47.927
2 hours for code golf? Some alternatives seem shorter in the few hours since... That's a mite quick, or am I missing something? – WernerCD – 2013-04-09T03:57:24.153
1@WernerCD I'm sure the OP will change who gets the green tick when he comes back to check on the new responses. – Gareth – 2013-04-09T07:15:52.960
2Not specifying a language really trivialises this challenge for me. As seen below, interpreted languages with a focus on high order text manipulation functions always get the shortest results.
What is to stop me throwing together my own interpreter with a single function, ip(). My compete algorithm is now 'ip:i'. 4 characters. done. – Gusdor – 2013-04-09T08:11:19.863
3
@Gusdor see J and GolfScript suck all the enjoyment out of Code Golf and Language Handicap and related questions on this site's meta.
– AakashM – 2013-04-09T08:25:20.920Gareth: You're right, I do. Gusdor: I would think 'no custom language' is an implicit rule. Of course, you bring up a fair point. WernerCD: I do keep an eye on this, but I have to sleep (I am a mere mortal.) – Andrew Gray – 2013-04-09T13:35:37.537
I was under the impression that the
green tick
can't be changed after a set amount of time. Different between sites? My misunderstanding? If you can change the green tick to keep current with the leader, then I stand corrected :) – WernerCD – 2013-04-19T19:23:44.247