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×ばつ⊃⍵⌽∊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)
×ばつ 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
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.
⍕,{2↑'thstndrd×ばつ⊃⍵⌽∊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,2,3,4,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],
[1,2,3,4,0,0,0,0,0,0],
⋮ (5 more)
[1,2,3,4,0,0,0,0,0,0]]
∊ εnlist (flatten);
[1,2,3,4,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,
1,2,3,4,0,0,0,0,0,0,
⋮ (50 more)
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)
×ばつ 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
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×ばつ⊃⍵⌽∊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;
[[0,1,2,3,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,1,2,3,0,0,0,0,0,0],
[0,1,2,3,0,0,0,0,0,0],
⋮ (5 more)
[0,1,2,3,0,0,0,0,0,0]]
∊ εnlist (flatten);
[0,1,2,3,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,1,2,3,0,0,0,0,0,0,
0,1,2,3,0,0,0,0,0,0,
⋮ (50 more)
0,1,2,3,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)
×ばつ 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
#Dyalog APL , (削除) 38 (削除ここまで) 36 bytes
⍕,{⊃⌽↓⍵2⍴('stndrd'/⍨9≥20|⍵),14⍴'th'}
APL (Dyalog Unicode) , (削除) 38 (削除ここまで) 36 bytes
Works by generating two-letter strings for all numbers upThanks to the given one, then returns the last string. If the given number is 9 or up, it does not generating any st/nd/rd's at all, so 11th/12th/13th become rightngn for fixing a bug while maintaining byte count.
This wholeAnonymous tacit prefix function is one single so-called fork : it applies the. Requires ⍕⎕IO function (which makes a number into a stringIndex Origin) set to the argument, and applies the anonymous 0, which is default on many systems.
⍕,{2↑'thstndrd×ばつ⊃⍵⌽∊1 0 8\⊂10↑⍳4}
{...} function anonymous lambda; (explained below) to the⍵ is argument:
⍳4 first four ɩndices; [0,1,2,3]
10↑ take first ten elements from that, and then it concatenatespadding with zeros: ([0,1,2,3,0,0,0,0,0,0]) the two results.
Explanation for the {...} function:⊂ enclose to treat as single element; [[0,1,2,3,0,0,0,0,0,0]]
14⍴'th'1 0 8\ recycle the letters until expand to one copy, a string of length 14 is reached
prototypical copy (all-zero), eight copies;
([[1,2,3,4,0,0,0,0,0,0],...) [0,0,0,0,0,0,0,0,0,0], prepends the parenthesized value
20|⍵ [1,2,3,4,0,0,0,0,0,0], the remainder when divided by 20
9≥ [1,2,3,4,0,0,0,0,0,0], boolean if 9 is greater than or equal to
⋮ (5 more)'stndrd'/⍨ [1,2,3,4,0,0,0,0,0,0]] the string if true; an empty string if false
∊εnlist (flatten);
⍵2⍴[1,2,3,4,0,0,0,0,0,0, makes into an argument-by-2 table
↓ 0,0,0,0,0,0,0,0,0,0, transforms the table into a list of strings
⊃⌽ 1,2,3,4,0,0,0,0,0,0, last sting 1,2,3,4,0,0,0,0,0,0,
⋮ (50 more) 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 (literallyi.e. the argument-mod-100'th number)
×ばつ 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 reversed list)
remaining characters
⍕, concatenate the stringified argument to that
#Dyalog APL , (削除) 38 (削除ここまで) 36 bytes
⍕,{⊃⌽↓⍵2⍴('stndrd'/⍨9≥20|⍵),14⍴'th'}
Works by generating two-letter strings for all numbers up to the given one, then returns the last string. If the given number is 9 or up, it does not generating any st/nd/rd's at all, so 11th/12th/13th become right.
This whole function is one single so-called fork : it applies the ⍕ function (which makes a number into a string) to the argument, and applies the anonymous {...} function (explained below) to the argument, and then it concatenates (,) the two results.
Explanation for the {...} function:
14⍴'th' recycle the letters until a string of length 14 is reached
(...), prepends the parenthesized value
20|⍵ the remainder when divided by 20
9≥ boolean if 9 is greater than or equal to
'stndrd'/⍨ the string if true; an empty string if false
⍵2⍴ makes into an argument-by-2 table
↓ transforms the table into a list of strings
⊃⌽ last sting (literally the first of the reversed list)
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.
⍕,{2↑'thstndrd×ばつ⊃⍵⌽∊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,2,3,4,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],
[1,2,3,4,0,0,0,0,0,0],
⋮ (5 more) [1,2,3,4,0,0,0,0,0,0]]
∊εnlist (flatten);
[1,2,3,4,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, 1,2,3,4,0,0,0,0,0,0,
⋮ (50 more) 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)
×ばつ 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
Dyalog APL, (削除) 38 (削除ここまで) 36 bytes
#Dyalog APL , (削除) 38 (削除ここまで) 36 bytes
⍕,{⊃⌽↓⍵2⍴('stndrd'/⍨9≥20|⍵),14⍴'th'}
Works by generating two-letter strings for all numbers up to the given one, then returns the last string. If the given number is 9 or up, it does not generating any st/nd/rd's at all, so 11th/12th/13th become right.
This whole function is one single so-called fork: it applies the ⍕ function (which makes a number into a string) to the argument, and applies the anonymous {...} function (explained below) to the argument, and then it concatenates (,) the two results.
Explanation for the {...} function:
14⍴'th' recycle the letters until a string of length 14 is reached
(...), prepends the parenthesized value
20|⍵ the remainder when divided by 20
9≥ boolean if 9 is greater than or equal to
'stndrd'/⍨ the string if true; an empty string if false
⍵2⍴ makes into an argument-by-2 table
↓ transforms the table into a list of strings
⊃⌽ last sting (literally the first of the reversed list)
Dyalog APL, (削除) 38 (削除ここまで) 36 bytes
⍕,{⊃⌽↓⍵2⍴('stndrd'/⍨9≥20|⍵),14⍴'th'}
Works by generating two-letter strings for all numbers up to the given one, then returns the last string. If the given number is 9 or up, it does not generating any st/nd/rd's at all, so 11th/12th/13th become right.
This whole function is one single so-called fork: it applies the ⍕ function (which makes a number into a string) to the argument, and applies the anonymous {...} function (explained below) to the argument, and then it concatenates (,) the two results.
Explanation for the {...} function:
14⍴'th' recycle the letters until a string of length 14 is reached
(...), prepends the parenthesized value
20|⍵ the remainder when divided by 20
9≥ boolean if 9 is greater than or equal to
'stndrd'/⍨ the string if true; an empty string if false
⍵2⍴ makes into an argument-by-2 table
↓ transforms the table into a list of strings
⊃⌽ last sting (literally the first of the reversed list)
#Dyalog APL , (削除) 38 (削除ここまで) 36 bytes
⍕,{⊃⌽↓⍵2⍴('stndrd'/⍨9≥20|⍵),14⍴'th'}
Works by generating two-letter strings for all numbers up to the given one, then returns the last string. If the given number is 9 or up, it does not generating any st/nd/rd's at all, so 11th/12th/13th become right.
This whole function is one single so-called fork: it applies the ⍕ function (which makes a number into a string) to the argument, and applies the anonymous {...} function (explained below) to the argument, and then it concatenates (,) the two results.
Explanation for the {...} function:
14⍴'th' recycle the letters until a string of length 14 is reached
(...), prepends the parenthesized value
20|⍵ the remainder when divided by 20
9≥ boolean if 9 is greater than or equal to
'stndrd'/⍨ the string if true; an empty string if false
⍵2⍴ makes into an argument-by-2 table
↓ transforms the table into a list of strings
⊃⌽ last sting (literally the first of the reversed list)