Outputting ordinal numbers (1st, 2nd, 3rd) I would like to generate (as a return result of a function, or simply as the output of a program) the ordinal suffix of a positive integer concatenated to the number.

Samples:

1st  
2nd  
3rd  
4th  
...  
11th  
12th  
13th  
...  
20th  
21st
22nd
23rd
24th


And so on, with the suffix repeating the initial 1-10 subpattern every 10 until 100, where the pattern ultimately starts over.

The input would be the number and the output the ordinal string as shown above.

What is the smallest algorithm for this?
Python 2, 49 bytes

lambda n:`n`+'tsnrhtdd'[n%5*(n%100^15&gt;4&gt;n%10)::4]


An anonymous function. A full program would be counted at 55 bytes. 

'tsnrhtdd'[i::4] encodes the suffixes th st nd rd for values of i from 0 to 3. Given this, all we need is a way to map the values of n to the index of the corresponding suffix, i. A straightforward expression that works is (n%10)*(n%10&lt;4 and 10&lt;n%100&lt;14). We can easily shorten this by dropping the first set of parentheses and observing that n%5 gives the same results as n%10 for the values of n with the special suffixes. With a bit of trial and error, one may also shorten 10&lt;n%100&lt;14 to n%100^15&gt;4, which can be chained with the other conditional to save even more bytes.