Palindrome detection: Difference between revisions
Content added Content deleted
Langurmonkey (talk | contribs) |
(added Emacs Lisp code that works with inexact palindromes) |
||
Line 2,018: | Line 2,018: | ||
<syntaxhighlight lang="lisp">(defun palindrome (s) |
<syntaxhighlight lang="lisp">(defun palindrome (s) |
||
(string= s (reverse s)))</syntaxhighlight> |
(string= s (reverse s)))</syntaxhighlight> |
||
The version below will work correctly with inexact palindromes, as defined in this exercise: |
|||
<pre> |
|||
(defun test-if-palindrome (text) |
|||
(setq text (replace-regexp-in-string "[[:space:][:punct:]]" "" text)) ; remove spaces and punctuation, by replacing them with nothing |
|||
(string-equal-ignore-case text (reverse text))) ; ignore case when looking at reversed text |
|||
</pre> |
|||
{{out}} |
|||
<pre> |
|||
(test-if-palindrome "A man, a plan, a canal, Panama") |
|||
t |
|||
</pre> |
|||
=={{header|Erlang}}== |
=={{header|Erlang}}== |