N'th: Difference between revisions

1,624 bytes added ,  6 years ago
+Stata
(+Stata)
Line 2,469:
ORA-01854: julian date must be between 1 and 5373484
</pre>
 
=={{header|Stata}}==
We reuse here the '''maps''' function defined in the task [[Apply a callback to an array]].
 
<lang stata>mata
function maps(f,a) {
nr = rows(a)
nc = cols(a)
b = J(nr,nc,"")
for (i=1;i<=nr;i++) {
for (j=1;j<=nc;j++) b[i,j] = (*f)(a[i,j])
}
return(b)
}
 
function nth(n) {
k = max((min((mod(n-1,10)+1,4)),4*(mod(n-10,100)<10)))
return(strofreal(n)+"'"+("st","nd","rd","th")[k])
}
 
maps(&nth(),((0::25),(250::275),(1000::1025)))
end</lang>
 
'''Output:'''
 
<pre> 1 2 3
+-------------------------------+
1 | 0'th 250'th 1000'th |
2 | 1'st 251'st 1001'st |
3 | 2'nd 252'nd 1002'nd |
4 | 3'rd 253'rd 1003'rd |
5 | 4'th 254'th 1004'th |
6 | 5'th 255'th 1005'th |
7 | 6'th 256'th 1006'th |
8 | 7'th 257'th 1007'th |
9 | 8'th 258'th 1008'th |
10 | 9'th 259'th 1009'th |
11 | 10'th 260'th 1010'th |
12 | 11'th 261'st 1011'th |
13 | 12'th 262'nd 1012'th |
14 | 13'th 263'rd 1013'th |
15 | 14'th 264'th 1014'th |
16 | 15'th 265'th 1015'th |
17 | 16'th 266'th 1016'th |
18 | 17'th 267'th 1017'th |
19 | 18'th 268'th 1018'th |
20 | 19'th 269'th 1019'th |
21 | 20'th 270'th 1020'th |
22 | 21'st 271'st 1021'st |
23 | 22'nd 272'nd 1022'nd |
24 | 23'rd 273'rd 1023'rd |
25 | 24'th 274'th 1024'th |
26 | 25'th 275'th 1025'th |
+-------------------------------+</pre>
 
 
=={{header|Swift}}==
1,336

edits