tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
27
Task/Palindrome-detection/GAP/palindrome-detection.gap
Normal file
27
Task/Palindrome-detection/GAP/palindrome-detection.gap
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
ZapGremlins := function(s)
|
||||
local upper, lower, c, i, n, t;
|
||||
upper := "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
lower := "abcdefghijklmnopqrstuvwxyz";
|
||||
t := [ ];
|
||||
i := 1;
|
||||
for c in s do
|
||||
n := Position(upper, c);
|
||||
if n <> fail then
|
||||
t[i] := lower[n];
|
||||
i := i + 1;
|
||||
else
|
||||
n := Position(lower, c);
|
||||
if n <> fail then
|
||||
t[i] := c;
|
||||
i := i + 1;
|
||||
fi;
|
||||
fi;
|
||||
od;
|
||||
return t;
|
||||
end;
|
||||
|
||||
IsPalindrome := function(s)
|
||||
local t;
|
||||
t := ZapGremlins(s);
|
||||
return t = Reversed(t);
|
||||
end;
|
||||
Loading…
Add table
Add a link
Reference in a new issue