How to resolve the algorithm Palindrome detection step by step in the AWK programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Palindrome detection step by step in the AWK 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 AWK programming language
Source code in the awk programming language
function is_palindro(s)
{
if ( s == reverse(s) ) return 1
return 0
}
function is_palindro_r(s)
{
if ( length(s) < 2 ) return 1
if ( substr(s, 1, 1) != substr(s, length(s), 1) ) return 0
return is_palindro_r(substr(s, 2, length(s)-2))
}
BEGIN {
pal = "ingirumimusnocteetconsumimurigni"
print is_palindro(pal)
print is_palindro_r(pal)
}
You may also check:How to resolve the algorithm Comments step by step in the 11l programming language
You may also check:How to resolve the algorithm 100 doors step by step in the Red programming language
You may also check:How to resolve the algorithm Palindrome dates step by step in the 11l programming language
You may also check:How to resolve the algorithm String length step by step in the xTalk programming language
You may also check:How to resolve the algorithm Left factorials step by step in the Ruby programming language