N'th: Difference between revisions

18 bytes added ,  4 years ago
Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 110:
 
</pre>
 
 
=={{header|AppleScript}}==
Line 509 ⟶ 508:
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
Set [1000,1025] :
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
 
=={{header|C sharp|C#}}==
{{trans|Ruby}}
<lang csharp>
class Program
{
private static string Ordinalize(int i)
{
i = Math.Abs(i);
 
if (new[] {11, 12, 13}.Contains(i%100))
return i + "th";
 
switch (i%10)
{
case 1:
return i + "st";
case 2:
return i + "nd";
case 3:
return i + "rd";
default:
return i + "th";
}
}
 
static void Main()
{
Console.WriteLine(string.Join(" ", Enumerable.Range(0, 26).Select(Ordinalize)));
Console.WriteLine(string.Join(" ", Enumerable.Range(250, 16).Select(Ordinalize)));
Console.WriteLine(string.Join(" ", Enumerable.Range(1000, 26).Select(Ordinalize)));
}
}
</lang>
 
{{Out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
 
Line 561 ⟶ 599:
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
 
=={{header|C sharp|C#Clojure}}==
{{trans|Ruby}}
<lang csharp>
class Program
{
private static string Ordinalize(int i)
{
i = Math.Abs(i);
 
if (new[] {11, 12, 13}.Contains(i%100))
return i + "th";
 
switch (i%10)
{
case 1:
return i + "st";
case 2:
return i + "nd";
case 3:
return i + "rd";
default:
return i + "th";
}
}
 
static void Main()
{
Console.WriteLine(string.Join(" ", Enumerable.Range(0, 26).Select(Ordinalize)));
Console.WriteLine(string.Join(" ", Enumerable.Range(250, 16).Select(Ordinalize)));
Console.WriteLine(string.Join(" ", Enumerable.Range(1000, 26).Select(Ordinalize)));
}
}
</lang>
 
{{Out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
 
=={{Header|Clojure}}==
<lang clojure>
(defn n-th [n]
Line 732 ⟶ 731:
</pre>
 
=={{Headerheader|D}}==
{{trans|Python}}
<lang d>import std.stdio, std.string, std.range, std.algorithm;
Line 750 ⟶ 749:
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
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|Elena}}==
{{trans|C#}}
Line 854:
1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
=={{header|F_Sharp|F#}}==
<lang fsharp>open System
Line 1,078 ⟶ 1,079:
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th
1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
 
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=6d60749ae886a37f128e75cffc6c7118 Click this link to run this code]'''
Line 1,340 ⟶ 1,342:
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th </pre>
 
 
=={{header|JavaScript}}==
Line 1,499 ⟶ 1,500:
1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
 
=={{Headerheader|Kotlin}}==
<lang scala>fun Int.ordinalAbbrev() =
if (this % 100 / 10 == 1) "th"
Line 1,656 ⟶ 1,657:
{"1000th", "1001st", "1002nd", "1003rd", "1004th", "1005th", "1006th", "1007th", "1008th", "1009th", "1010th", "1011th", "1012th", "1013th", "1014th", "1015th", "1016th", "1017th", "1018th", "1019th", "1020th", "1021st", "1022nd", "1023rd", "1024th", "1025th"}</pre>
 
=={{Headerheader|MATLAB}}==
<lang MATLAB>function s = nth(n)
tens = mod(n, 100);
Line 1,832 ⟶ 1,833:
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>
 
=={{Headerheader|Nim}}==
{{trans|Python}}
<lang nim>const suffix = ["th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"]
Line 1,903 ⟶ 1,904:
</pre>
 
=={{Headerheader|PARI/GP}}==
(Spurious apostrophes intentionally omitted, following Perl 6.)
 
Line 1,916 ⟶ 1,917:
%3 = ["1000th", "1001st", "1002nd", "1003rd", "1004th", "1005th", "1006th", "1007th", "1008th", "1009th", "1010th", "1011th", "1012th", "1013th", "1014th", "1015th", "1016th", "1017th", "1018th", "1019th", "1020th", "1021st", "1022nd", "1023rd", "1024th", "1025th"]
%4 = ["111th", "1012th"]</pre>
 
=={{Header|Pascal}}==
=={{header|Pascal}}==
nearly copy of [[N'th#Ada|Ada]]
<lang pascal>Program n_th;
Line 1,957 ⟶ 1,959:
..1001st 1002nd 1003rd 1004th..1011th..1013th..1021st 1022nd 1023rd 1024th
</pre>
 
=={{Header|Perl}}==
=={{header|Perl}}==
{{Trans|Perl 6}}
Requires Perl 5.10 or newer for the Defined OR operator (//).
Line 1,984 ⟶ 1,987:
print ordinate($i),"\n";
}</lang>
 
=={{header|Perl 6}}==
(Spurious apostrophes intentionally omitted.)
<lang perl6>my %irregulars = <1 st 2 nd 3 rd>, (11..13 X=> 'th');
 
sub nth ($n) { $n ~ ( %irregulars{$n % 100} // %irregulars{$n % 10} // 'th' ) }
 
say .list».&nth for [^26], [250..265], [1000..1025];</lang>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
If you want to get Unicodally fancy, use this version instead:
<lang perl6>my %irregulars = <1 ˢᵗ 2 ⁿᵈ 3 ʳᵈ>, (11..13 X=> 'ᵗʰ');
 
sub nth ($n) { $n ~ ( %irregulars{$n % 100} // %irregulars{$n % 10} // 'ᵗʰ' ) }
 
say .list».&nth for [^26], [250..265], [1000..1025];</lang>
{{out}}
<blockquote>0ᵗʰ 1ˢᵗ 2ⁿᵈ 3ʳᵈ 4ᵗʰ 5ᵗʰ 6ᵗʰ 7ᵗʰ 8ᵗʰ 9ᵗʰ 10ᵗʰ 11ᵗʰ 12ᵗʰ 13ᵗʰ 14ᵗʰ 15ᵗʰ 16ᵗʰ 17ᵗʰ 18ᵗʰ 19ᵗʰ 20ᵗʰ 21ˢᵗ 22ⁿᵈ 23ʳᵈ 24ᵗʰ 25ᵗʰ<br>
250ᵗʰ 251ˢᵗ 252ⁿᵈ 253ʳᵈ 254ᵗʰ 255ᵗʰ 256ᵗʰ 257ᵗʰ 258ᵗʰ 259ᵗʰ 260ᵗʰ 261ˢᵗ 262ⁿᵈ 263ʳᵈ 264ᵗʰ 265ᵗʰ<br>
1000ᵗʰ 1001ˢᵗ 1002ⁿᵈ 1003ʳᵈ 1004ᵗʰ 1005ᵗʰ 1006ᵗʰ 1007ᵗʰ 1008ᵗʰ 1009ᵗʰ 1010ᵗʰ 1011ᵗʰ 1012ᵗʰ 1013ᵗʰ 1014ᵗʰ 1015ᵗʰ 1016ᵗʰ 1017ᵗʰ 1018ᵗʰ 1019ᵗʰ 1020ᵗʰ 1021ˢᵗ 1022ⁿᵈ 1023ʳᵈ 1024ᵗʰ 1025ᵗʰ</blockquote>
 
=={{header|Phix}}==
Line 2,038 ⟶ 2,019:
</pre>
 
=={{Headerheader|PHP}}==
<lang PHP>function nth($num) {
$os = "th";
Line 2,071 ⟶ 2,052:
</pre>
 
=={{Headerheader|PicoLisp}}==
<lang PicoLisp>(de rangeth (A B)
(mapcar
Line 2,231 ⟶ 2,212:
</pre>
 
=={{Headerheader|Python}}==
<lang python>_suffix = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th']
 
Line 2,273 ⟶ 2,254:
</pre>
 
=={{Headerheader|R}}==
{{trans|Python}}
Note that R vectors are 1-indexed.
Line 2,340 ⟶ 2,321:
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
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|Raku}}==
(formerly Perl 6)
(Spurious apostrophes intentionally omitted.)
<lang perl6>my %irregulars = <1 st 2 nd 3 rd>, (11..13 X=> 'th');
 
sub nth ($n) { $n ~ ( %irregulars{$n % 100} // %irregulars{$n % 10} // 'th' ) }
 
say .list».&nth for [^26], [250..265], [1000..1025];</lang>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
If you want to get Unicodally fancy, use this version instead:
<lang perl6>my %irregulars = <1 ˢᵗ 2 ⁿᵈ 3 ʳᵈ>, (11..13 X=> 'ᵗʰ');
 
sub nth ($n) { $n ~ ( %irregulars{$n % 100} // %irregulars{$n % 10} // 'ᵗʰ' ) }
 
say .list».&nth for [^26], [250..265], [1000..1025];</lang>
{{out}}
<blockquote>0ᵗʰ 1ˢᵗ 2ⁿᵈ 3ʳᵈ 4ᵗʰ 5ᵗʰ 6ᵗʰ 7ᵗʰ 8ᵗʰ 9ᵗʰ 10ᵗʰ 11ᵗʰ 12ᵗʰ 13ᵗʰ 14ᵗʰ 15ᵗʰ 16ᵗʰ 17ᵗʰ 18ᵗʰ 19ᵗʰ 20ᵗʰ 21ˢᵗ 22ⁿᵈ 23ʳᵈ 24ᵗʰ 25ᵗʰ<br>
250ᵗʰ 251ˢᵗ 252ⁿᵈ 253ʳᵈ 254ᵗʰ 255ᵗʰ 256ᵗʰ 257ᵗʰ 258ᵗʰ 259ᵗʰ 260ᵗʰ 261ˢᵗ 262ⁿᵈ 263ʳᵈ 264ᵗʰ 265ᵗʰ<br>
1000ᵗʰ 1001ˢᵗ 1002ⁿᵈ 1003ʳᵈ 1004ᵗʰ 1005ᵗʰ 1006ᵗʰ 1007ᵗʰ 1008ᵗʰ 1009ᵗʰ 1010ᵗʰ 1011ᵗʰ 1012ᵗʰ 1013ᵗʰ 1014ᵗʰ 1015ᵗʰ 1016ᵗʰ 1017ᵗʰ 1018ᵗʰ 1019ᵗʰ 1020ᵗʰ 1021ˢᵗ 1022ⁿᵈ 1023ʳᵈ 1024ᵗʰ 1025ᵗʰ</blockquote>
 
=={{header|REXX}}==
Line 2,420 ⟶ 2,424:
1000th, 1001st, 1002nd, 1003rd, 1004th, 1005th, 1006th, 1007th, 1008th, 1009th, 1010th, 1011th, 1012th, 1013th, 1014th, 1015th, 1016th, 1017th, 1018th, 1019th, 1020th, 1021st, 1022nd, 1023rd, 1024th, 1025th
</pre>
 
 
=={{header|Rust}}==
10,333

edits