How to resolve the algorithm Palindrome detection step by step in the MiniScript programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Palindrome detection step by step in the MiniScript 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 MiniScript programming language

Source code in the miniscript programming language

isPalindrome = function(s)
    // convert to lowercase, and strip non-letters
    stripped = ""
    for c in s.lower
    	if c >= "a" and c <= "z" then stripped = stripped + c
    end for

    // check palindromity
    mid = floor(stripped.len/2)
    for i in range(0, mid)
    	if stripped[i] != stripped[-i - 1] then return false
    end for
    return true
end function

testStr = "Madam, I'm Adam"
answer = [testStr, "is"]
if not isPalindrome(testStr) then answer.push "NOT"
answer.push "a palindrome"
print answer.join

  

You may also check:How to resolve the algorithm Determinant and permanent step by step in the Maple programming language
You may also check:How to resolve the algorithm Detect division by zero step by step in the MATLAB programming language
You may also check:How to resolve the algorithm Digital root step by step in the OCaml programming language
You may also check:How to resolve the algorithm Largest int from concatenated ints step by step in the Bracmat programming language
You may also check:How to resolve the algorithm HTTP step by step in the Erlang programming language