Ad

A palindrome is a word or phrase that is read the same forward as backwards

Some popular examples of palindrome words are "racecar" and "kayak", and phrases are "a man a plan a canal panama" and "madam im adam"

Some phrases are not as simple as reversing a word

Write a function that returns true if a phrase is a palindrome and false if it is not, case and spaces doesn't matter.

'racecar' == True
'Racecar' == True
'racecars' == False

'a man a plan panama' == True
'a Man a plan panama' == True
'a man 2 plan panama' == False
def ispalindrome(p):
    if p.replace(' ', '').upper()==p.replace(' ', '').upper()[::-1]: return True
    return False
Code
Diff
  • import string
    def SameCase(a, b):
        if a not in string.ascii_letters or b not in string.ascii_letters:
            return -1
        
        return int(a.isupper() == b.isupper())
    • public class Kata {
    • public static int SameCase(char a, char b) {
    • import string
    • def SameCase(a, b):
    • if a not in string.ascii_letters or b not in string.ascii_letters:
    • return -1
    • string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    • char tempA = a;
    • char tempB = b;
    • if((!letters.Contains(tempA = char.ToUpper(tempA)) && letters.Contains(tempB = char.ToUpper(tempB))) ||
    • (!letters.Contains(tempB = char.ToUpper(tempB)) && letters.Contains(tempA = char.ToUpper(tempA))) ||
    • (!letters.Contains(tempA = char.ToUpper(tempA)) && !letters.Contains(tempB = char.ToUpper(tempB)))) return -1;
    • if(char.IsUpper(a) && char.IsUpper(b)){
    • return 1;
    • } else if (char.IsLower(a) && char.IsLower(b)){
    • return 1;
    • } else {
    • return 0;
    • }
    • }
    • }
    • return int(a.isupper() == b.isupper())