Palindrome detection: Difference between revisions
→{{header|ed}}: Minor grammatical fix
Not a robot (talk | contribs) (add Refal) |
(→{{header|ed}}: Minor grammatical fix) |
||
(7 intermediate revisions by 4 users not shown) | |||
Line 1,911:
;;(equal? (string->list string) (reverse (string->list string)))))
</syntaxhighlight>
=={{header|ed}}==
A limitation: due to ed having no built-in loops, the part with palindrome beginning/end matching has to be repeated as many times as there are palindrome levels. As a sane default, 15 is used here.
# by Artyom Bologov
H
,p
g/^(.)(.+)\1$/s//\2/
g/^(.)(.+)\1$/s//\2/
g/^(.)(.+)\1$/s//\2/
g/^(.)(.+)\1$/s//\2/
g/^(.)(.+)\1$/s//\2/
g/^(.)(.+)\1$/s//\2/
g/^(.)(.+)\1$/s//\2/
g/^(.)(.+)\1$/s//\2/
g/^(.)(.+)\1$/s//\2/
g/^(.)(.+)\1$/s//\2/
g/^(.)(.+)\1$/s//\2/
g/^(.)(.+)\1$/s//\2/
g/^(.)(.+)\1$/s//\2/
g/^(.)(.+)\1$/s//\2/
g/^(.)(.+)\1$/s//\2/
v/^(.)(.+)\1$|^.$/s/.*/Not a palindrome!/
g/^.$/s//Palindrome!/
,p
Q
</syntaxhighlight>
{{out}}
<pre>$ cat palindrome.ed | ed -lEGs palindrome.input
rotor
racecar
level
rosetta
Palindrome!
Palindrome!
Palindrome!
Not a palindrome!</pre>
=={{header|Eiffel}}==
Line 3,259 ⟶ 3,300:
=={{header|langur}}==
<syntaxhighlight lang="langur">
val ispal = fn s:len(s) > 0 and s == reverse(s)
val
"": false,
"z": true,
Line 3,278 ⟶ 3,320:
}
for
val
writeln
}
▲}</syntaxhighlight>
</syntaxhighlight>
{{out}}
Line 4,129 ⟶ 4,172:
writeln('input was not palindrome');
end.</syntaxhighlight>
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
function IsPalindrome(s: string) := s = s[::-1];
begin
Println(IsPalindrome('arozaupalanalapuazora'));
Println(IsPalindrome('abcd'));
end.
</syntaxhighlight>
{{out}}
<pre>
True
False
</pre>
=={{header|Perl}}==
Line 5,996 ⟶ 6,054:
Does not ignore spaces.
<syntaxhighlight lang="uiua">≍⇌."tacocat"</syntaxhighlight>
===Extra Credit===
Ignores whitespace, converts A-Z to lowercase, only checks a-z, includes tests.
<syntaxhighlight lang="uiua">IsPal ← ≍⇌.+×32<@a.▽:⟜∊:/⊂+⊙¤"Aa"⇡26
IsPal "A man, a plan, a canal: Panama!"
</syntaxhighlight>
=={{header|UNIX Shell}}==
|