N'th

From Rosetta Code
Revision as of 06:20, 20 February 2021 by Drkameleon (talk | contribs)

Arturo

<lang rebol>suffixes: ["th" "st" "nd" "rd" "th" "th" "th" "th" "th" "th"]

nth: function [n][

   if? or? 100 >= n%100
           20 < n%100 
           -> (to :string n) ++ "'" ++ suffixes \ n%10
   else    -> (to :string n) ++ "'th"

]

loop range.step:250 0 1000 'j [

   loop j..j+24 'i ->
       prints (nth i)++" "
   print ""

]</lang>

Output:
0'th 1'st 2'nd 3'rd 4'th 5'th 6'th 7'th 8'th 9'th 10'th 11'st 12'nd 13'rd 14'th 15'th 16'th 17'th 18'th 19'th 20'th 21'st 22'nd 23'rd 24'th 
250'th 251'st 252'nd 253'rd 254'th 255'th 256'th 257'th 258'th 259'th 260'th 261'st 262'nd 263'rd 264'th 265'th 266'th 267'th 268'th 269'th 270'th 271'st 272'nd 273'rd 274'th 
500'th 501'st 502'nd 503'rd 504'th 505'th 506'th 507'th 508'th 509'th 510'th 511'st 512'nd 513'rd 514'th 515'th 516'th 517'th 518'th 519'th 520'th 521'st 522'nd 523'rd 524'th 
750'th 751'st 752'nd 753'rd 754'th 755'th 756'th 757'th 758'th 759'th 760'th 761'st 762'nd 763'rd 764'th 765'th 766'th 767'th 768'th 769'th 770'th 771'st 772'nd 773'rd 774'th 
1000'th 1001'st 1002'nd 1003'rd 1004'th 1005'th 1006'th 1007'th 1008'th 1009'th 1010'th 1011'st 1012'nd 1013'rd 1014'th 1015'th 1016'th 1017'th 1018'th 1019'th 1020'th 1021'st 1022'nd 1023'rd 1024'th