Write a function/method/subroutine/... that when given an integer greater than or equal to zero returns a string of the number followed by an apostrophe then the ordinal suffix.



Example

Returns would include 1'st 2'nd 3'rd 11'th 111'th 1001'st 1012'th



Task

Use your routine to show here the output for at least the following (inclusive) ranges of integer inputs:
0..25, 250..265, 1000..1025


Note: apostrophes are now optional to allow correct apostrophe-less English.




constant ordinals = {"th","st","nd","rd"}
 
function Nth(integer n, bool apostrophe=false)
    integer mod10 = mod(n,10)+1
    if mod10>4 or mod(n,100)=mod10+9 then mod10 = 1 end if
    return sprintf("%d%s",{n,repeat('\'',apostrophe)&ordinals[mod10]})
end function
 
constant ranges = {{0,25},{250,265},{1000,1025}}
for i=1 to length(ranges) do
    for j=ranges[i][1] to ranges[i][2] do
        if mod(j,10)=0 then puts(1,"\n") end if
        printf(1," %6s",{Nth(j,i=2)})
    end for
    puts(1,"\n")
end for
