def ordinal(number):
    """Returns the string ordinal for the input number.
    Algorithm from Gareth's solution at:
    http://codegolf.stackexchange.com/questions/4707/outputting-ordinal-numbers-1st-2nd-3rd
    """
    k = number % 10
    return "{}{}".format(number,
                         "tsnrhtdd"[(number / 10 % 10 != 1) * (k < 4) * k::4])