Rotating Letters (CCC/2013/J2)


An artist wants to construct a sign whose letters will rotate freely in the breeze. In order to do this, she must only use letters that are not changed by rotation of 180 degrees: I, O, S, H, Z, X, and N.

Define a function, Rotated, that reads a word and determines whether it can be used on the sign.  Your input will be a string containing exactly one word, in all caps.  Your output should be True if the word can be used and False if it cannot be used.

Original problem description on CEMC website.


Sample Output:

>>> Rotated('SHINS')

>>> Rotated('MOM')

>>> Rotated(35,27,78)

Background Information

If an object can be rotated and still look the same, we say that it has rotational symmetry.  If it can be rotated 180 degrees and look the same, we say it has rotational symmetry of order 2, because it will take two rotations to return the object to its original position.

The capital letter “Z” has rotational symmetry, because it can be rotated less than one full turn and still look the same. Its order of rotational symmetry is 2, because you must perform the operation above twice to return the red dot to its original position.

The letter ‘M’ does not have rotational symmetry; it has a different symmetry called linear (or reflective) symmetry.

Programming Tools (with Python examples)

Boolean functions.  Many simple functions are designed to decide whether a statement is true, and then return a Boolean value (True or False).  The function below decides whether a number (x) is greater than 10 or not.

def GreaterThanTen(x):
    if x>10:
        return True
        return False

Sample outputs:

>>> GreaterThanTen(5)

>>> GreaterThanTen(10)


>>> GreaterThanTen('fifteen')

for.  Suppose you want to perform the same operation on a bunch of different things.  The for statement is very helpful – especially if you don’t know how many things there are.

def OneTwoThree():
    for a in {1,2,3}:
def SpellOut(Word):
    for letter in Word:
def CountLetter(Word, LetterToCount):
    total = 0
    for letter in Word:
        if letter == LetterToCount:
            total = total + 1
    return total

Sample outputs:

>>> OneTwoThree()

>>> SpellOut('dog')

>>> CountLetter('apple', 'p')

Indices. You will find it useful to be able to tell your program to look at the 1st, 2nd, 3rd, 4th… letter of a word.  This is pretty easy (see the example below); the only trick to it is to remember that, by convention, we start counting at 0.  So ‘a’ is the 0th letter of apple.  You can use indices on explicit strings (like ‘apple’) as well as on variables (as long as the variable represents a data type that has indices).

Word = 'apple' #this declares a variable, word, whose value has been set to 'apple'.

Sample Output:

>>> 'apple'[3]

>>> Word[3]

>>> 'Word'[3]

Length.  In your programming language there is a way to find the length of a string.  The way to do this in Python is shown below.  Notice that len is a function.

Sample Output:

>>> len('apple')

>>> len('apple'[3])

>>> len(word) #remember that I earlier assigned the value 'apple' to the variable Word


Write a function that reads a word and determines whether the letters in the word are in alphabetical order.