Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

7 of 9
added 23 characters in body
Adám
  • 31.8k
  • 4
  • 131
  • 292

#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)

Adám
  • 31.8k
  • 4
  • 131
  • 292

AltStyle によって変換されたページ (->オリジナル) /