DNPotapov / Codewars-katas-

0 stars 0 forks source link

Shifter words (7 kyu) #20

Open DNPotapov opened 1 year ago

DNPotapov commented 1 year ago
def shifter(st): 
    key = ["H", "I", "N", "O", "S", "X", "Z", "M", "W"]
    mass = st.split()
    count = 0
    result = 0
    check_dublicate = []
    for item in mass:
        for i in item:
            if i in key:
                count += 1
        if count == len(item) and item not in check_dublicate:
            result += 1
            check_dublicate.append(item)
        count = 0
    return result
DNPotapov commented 1 year ago

You probably know that some characters written on a piece of paper, after turning this sheet 180 degrees, can be read, although sometimes in a different way. So, uppercase letters "H", "I", "N", "O", "S", "X", "Z" after rotation are not changed, the letter "M" becomes a "W", and Vice versa, the letter "W" becomes a "M".

We will call a word "shifter" if it consists only of letters "H", "I", "N", "O", "S", "X", "Z", "M" and "W". After turning the sheet, this word can also be read, although in a different way. So, the word "WOW "turns into the word "MOM". On the other hand, the word "HOME" is not a shifter.

Find the number of unique shifter words in the input string (without duplicates). All shifters to be counted, even if they are paired (like "MOM" and "WOW"). String contains only uppercase letters.

Examples shifter("SOS IN THE HOME") == 2 # shifter words are "SOS" and "IN" shifter("WHO IS SHIFTER AND WHO IS NO") == 3 # shifter words are "WHO", "IS", "NO" shifter("TASK") == 0 # no shifter words shifter("") == 0 # no shifter words in empty string

DNPotapov commented 1 year ago

https://www.codewars.com/kata/603b2bb1c7646d000f900083