Jump to content

Palindrome detection: Difference between revisions

Add APL entry
(Add APL entry)
Line 147:
sequence "ingirumimusnocteetconsumimurigni" is a palindrome
</pre>
=={{header|APL}}==
 
NARS2000 APL, dynamic function "if the argument matches the reverse of the argument", with Unicode character support:
 
<lang APL> {⍵≡⌽⍵} 'abc'
0
{⍵≡⌽⍵} '⍋racecar⍋'
1</lang>
Or in tacit function form, a combination of three functions, right tack (echo), reverse, then the result of each compared with the middle one, match (equals):
<lang APL> (⊢≡⌽) 'abc'
0
(⊢≡⌽) 'nun'
1</lang>
An inexact version is harder, because uppercase and lowercase with Unicode awareness depends on APL interpreter; NARS2000 has no support for it. Classic case conversion means lookup up the letters in an alphabet of UppercaseLowercase, then mapping those positions into an UppercaseUppercase or LowercaseLowercase array. Remove non-A-Za-z first to get rid of punctuation, and get an inexact dynamic function with just English letter support:
<lang APL>inexact←{Aa←(⎕A,⎕a) ⋄ (⊢≡⌽)(⎕a,⎕a)[Aa⍳⍵/⍨⍵∊Aa]}
inexact 'abc,-cbA2z'
0
inexact 'abc,-cbA2'
1</lang>
Dyalog APL has a Unicode-aware uppercase/lowercase function (819 I-beam), AFAIK no support for looking up Unicode character classes.
=={{header|AppleScript}}==
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.