How to resolve the algorithm Palindrome detection step by step in the GAP programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Palindrome detection step by step in the GAP programming language
Table of Contents
Problem Statement
A palindrome is a phrase which reads the same backward and forward. Write a function or program that checks whether a given sequence of characters (or, if you prefer, bytes) is a palindrome. For extra credit:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Palindrome detection step by step in the GAP programming language
Source code in the gap programming language
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;
You may also check:How to resolve the algorithm Problem of Apollonius step by step in the CoffeeScript programming language
You may also check:How to resolve the algorithm Anonymous recursion step by step in the Elena programming language
You may also check:How to resolve the algorithm Chat server step by step in the Haskell programming language
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the TypeScript programming language
You may also check:How to resolve the algorithm Random numbers step by step in the PicoLisp programming language