How to resolve the algorithm Palindrome detection step by step in the Batch File programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Palindrome detection step by step in the Batch File 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 Batch File programming language
Source code in the batch programming language
@echo off
setlocal enabledelayedexpansion
set /p string=Your string :
set count=0
:loop
if "!%string%:~%count%,1!" neq "" (
set reverse=!%string%:~%count%,1!!reverse!
set /a count+=1
goto loop
)
set palindrome=isn't
if "%string%"=="%reverse%" set palindrome=is
echo %string% %palindrome% a palindrome.
pause
exit
@echo off
set /p testString=Your string (all same case please) :
call :isPalindrome result %testString: =%
if %result%==1 echo %testString% is a palindrome
if %result%==0 echo %testString% isn't a palindrome
pause
goto :eof
:isPalindrome
set %1=0
set string=%2
if "%string:~2,1%"=="" (
set %1=1
goto :eof
)
if "%string:~0,1%"=="%string:~-1%" (
call :isPalindrome %1 %string:~1,-1%
)
goto :eof
You may also check:How to resolve the algorithm Stern-Brocot sequence step by step in the C# programming language
You may also check:How to resolve the algorithm Dinesman's multiple-dwelling problem step by step in the Sidef programming language
You may also check:How to resolve the algorithm Benford's law step by step in the Factor programming language
You may also check:How to resolve the algorithm Trigonometric functions step by step in the D programming language
You may also check:How to resolve the algorithm Continued fraction step by step in the AutoHotkey programming language