N'th: Difference between revisions
Content deleted Content added
Added Lua version |
|||
Line 1,055:
1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th
1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
=={{header|Lua}}==
The apostrophe just looks weird if you ask me. No one did, obviously.
<lang Lua>
function getSuffix (n)
local lastTwo, lastOne = n % 100, n % 10
if lastTwo > 3 and lastTwo < 21 then return "th" end
if lastOne == 1 then return "st" end
if lastOne == 2 then return "nd" end
if lastOne == 3 then return "rd" end
return "th"
end
function Nth (n)
return n .. "'" .. getSuffix(n)
end
for n = 0, 25 do
print(Nth(n), Nth(n + 250), Nth(n + 1000))
end
</lang>
{{out}}
<pre>
0'th 250'th 1000'th
1'st 251'st 1001'st
2'nd 252'nd 1002'nd
3'rd 253'rd 1003'rd
4'th 254'th 1004'th
5'th 255'th 1005'th
6'th 256'th 1006'th
7'th 257'th 1007'th
8'th 258'th 1008'th
9'th 259'th 1009'th
10'th 260'th 1010'th
11'th 261'st 1011'th
12'th 262'nd 1012'th
13'th 263'rd 1013'th
14'th 264'th 1014'th
15'th 265'th 1015'th
16'th 266'th 1016'th
17'th 267'th 1017'th
18'th 268'th 1018'th
19'th 269'th 1019'th
20'th 270'th 1020'th
21'st 271'st 1021'st
22'nd 272'nd 1022'nd
23'rd 273'rd 1023'rd
24'th 274'th 1024'th
25'th 275'th 1025'th
</pre>
|