N'th: Difference between revisions

Content added Content deleted
(Add EasyLang)
Line 3,536: Line 3,536:
return "" + n + "'" + getSuffix(n) + " "
return "" + n + "'" + getSuffix(n) + " "
</syntaxhighlight>
</syntaxhighlight>

=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
===Readable version===
≪ IP DUP 10 MOD OVER 100 MOD 10 / IP → units tens
≪ →STR "'" +
IF units 1 ≥ units 3 ≤ AND tens 1 ≠ AND
THEN { "st" "nd" "rd" } units GET
ELSE "th"
END
+
'NTH' STO
===Compact version===
This version uses basic arithmetic instead of variable testing to determine when to apply the "st/nd/rd" exception.
≪ IP →STR LAST { "'th" "'st" "'nd" "'rd" }
OVER 10 MOD DUP 4 < * ROT 100 MOD 10 / IP 1 ≠ * 1 + GET +
'NTH' STO

≪ { } 3 ROLLD FOR j j NTH + NEXT ≫
'SHOW' STO
0 25 SHOW
250 265 SHOW
1000 1025 SHOW
{{out}}
<pre>
3: { "0'th" "1'st" "2'nd" "3'rd" "4'th" "5'th" "6'th" "7'th" "8'th" "9'th" "10'th" "11'th" "12'th" "13'th" "14'th" "15'th" "16'th" "17'th" "18'th" "19'th" "20'th" "21'st" "22'nd" "23'rd" "24'th" "25'th" }
2: { "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" }
1: { "1000'th" "1001'st" "1002'nd" "1003'rd" "1004'th" "1005'th" "1006'th" "1007'th" "1008'th" "1009'th" "1010'th" "1011'th" "1012'th" "1013'th" "1014'th" "1015'th" "1016'th" "1017'th" "1018'th" "1019'th" "1020'th" "1021'st" "1022'nd" "1023'rd" "1024'th" "1025'th" }
</pre>


=={{header|Ruby}}==
=={{header|Ruby}}==