Computer Science Canada

palindrome

Author:  scorpion1087 [ Thu Oct 30, 2003 4:27 pm ]
Post subject:  palindrome

how do you check if a palindrome is true

eg
mom will have 1 check because the m's cancel and whatever is in the middle is left over.

my email is scorpion1087@hotmail.com

ps how do you create a palindrome

Author:  Blade [ Thu Oct 30, 2003 5:16 pm ]
Post subject: 

umm... you'd have to use a reversed for loop and use two variables.... thats the easiest way
ex:
code:
var word1,word2:string(30):=""
word:="mom"
for decreasing i:1..length(word1)
  word2+=word1(i)
end for
if (word1 = word2) then
  %is a palindrome
end if


thats just one way, theres more but i think thats the easiest...

Author:  Andy [ Thu Oct 30, 2003 5:31 pm ]
Post subject: 

you could also do this
code:

var word :string:="mom"
for i:1..length(word) div 2
    for decreasing j: length(word)..length(word) div 2
        if word(i) not= word(j)
            put "no"
            return
        end if
    end for
end for

better than blade's method cuz u dont need a new var Laughing

Author:  Blade [ Sun Nov 02, 2003 1:41 am ]
Post subject: 

Blade wrote:
thats just one way, theres more but i think thats the easiest...


duh - didnt say it was the best


: