APL (Dyalog Unicode), 38 36 bytes
Thanks to ngn for fixing a bug while maintaining byte count.
Anonymous tacit prefix function. Requires ⎕IO
(Index Origin) set to 0
, which is default on many systems. Even works for 0!
⍕,{2↑'thstndrd'↓⍨2×⊃⍵⌽∊1 0 8\⊂10↑⍳4}
{
…}
anonymous lambda; ⍵
is argument:
⍳4
first four ɩndices; [0,1,2,3]
10↑
take first ten elements from that, padding with zeros: [0,1,2,3,0,0,0,0,0,0]
⊂
enclose to treat as single element; [[0,1,2,3,0,0,0,0,0,0]]
1 0 8\
expand to one copy, a prototypical copy (all-zero), eight copies;
[[1[[0,1,2,3,4,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[1[0,1,2,3,4,0,0,0,0,0,0],
[1[0,1,2,3,4,0,0,0,0,0,0],
⋮ (5 more)
[1[0,1,2,3,4,0,0,0,0,0,0]]
∊
ϵnlist (flatten);
[1[0,1,2,3,4,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,1,2,3,4,0,0,0,0,0,0,
0,1,2,3,4,0,0,0,0,0,0,
⋮ (50 more)
0,1,2,3,4,0,0,0,0,0,0]
⍵⌽
cyclically rotate left as many steps as indicated by the argument
⊃
pick the first number (i.e. the argument-mod-100'th number)
2×
multiply two by that (gives 0
, 2
, 4
, or 6
)
'thstndrd'↓⍨
drop that many characters from this string
2↑
take the first two of the remaining characters
⍕,
concatenate the stringified argument to that