Palindrome detection: Difference between revisions
Content added Content deleted
(added Emacs Lisp code that works with inexact palindromes) |
No edit summary |
||
Line 2,021: | Line 2,021: | ||
The version below will work correctly with inexact palindromes, as defined in this exercise: |
The version below will work correctly with inexact palindromes, as defined in this exercise: |
||
<syntaxhighlight lang="lisp"> |
|||
<pre> |
|||
(defun test-if-palindrome (text) |
(defun test-if-palindrome (text) |
||
(setq text (replace-regexp-in-string "[[:space:][:punct:]]" "" text)) ; remove spaces and punctuation, by replacing them with nothing |
(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 |
(string-equal-ignore-case text (reverse text))) ; ignore case when looking at reversed text |
||
</syntaxhighlight> |
|||
</pre> |
|||
{{out}} |
{{out}} |
||