Palindrome detection: Difference between revisions
Content added Content deleted
WillBAnders (talk | contribs) (Add Rhovas solution (string-based unicode safe & character-based)) |
(added RPL) |
||
Line 5,233: | Line 5,233: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|RPL}}== |
|||
≪ "" |
|||
OVER SIZE 1 '''FOR''' j |
|||
OVER j DUP SUB + -1 '''STEP''' |
|||
== |
|||
≫ ‘<span style="color:blue">XPAL?</span>’ STO |
|||
====Stretch==== |
|||
RPL does not support Unicode. To detect inexact palindromes, we just need a clean-up word: |
|||
≪ "" |
|||
1 3 PICK SIZE '''FOR''' j |
|||
OVER j DUP SUB |
|||
'''IF''' DUP "a" ≥ OVER "z" ≤ AND '''THEN''' NUM 32 - CHR '''END''' |
|||
'''IF''' DUP "A" ≥ OVER "Z" ≤ AND '''THEN''' + '''ELSE''' DROP '''END''' |
|||
'''NEXT''' SWAP DROP |
|||
≫ ‘<span style="color:blue">AZONLY</span>’ STO |
|||
≪ <span style="color:blue">AZONLY</span> "" |
|||
OVER SIZE 1 '''FOR''' j |
|||
OVER j DUP SUB + -1 '''STEP''' |
|||
== |
|||
≫ ‘<span style="color:blue">IPAL?</span>’ STO |
|||
"rotor" <span style="color:blue">XPAL?</span> |
|||
"In girum imus nocte et consumimur igni." <span style="color:blue">IPAL?</span> |
|||
{{out}} |
|||
<pre> |
|||
2: 1 |
|||
1: 1 |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||