N'th: Difference between revisions

4,843 bytes added ,  1 month ago
m
fix typo
m (fix typo)
 
(11 intermediate revisions by 8 users not shown)
Line 2,245:
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
procfunc$ nth num . ordinal$ .
num$last2 = num mod 100
lastTwoDigits$last = substr num$ len num$ - 1mod 210
lastDigit$if last2 >= substr11 num$and lenlast2 num$<= 113
return num & "th"
if lastTwoDigits$ = "11" or lastTwoDigits$ = "12" or lastTwoDigits$ = "13"
elif ordinal$last = num$ & "th"1
elif lastDigit$ = return num & "1st"
elif ordinal$last = num$ & "st"2
elif lastDigit$ = return num & "2nd"
elif ordinal$last = num$ & "nd"3
elif lastDigit$ = return num & "3rd"
ordinal$ = num$ & "rd"
else
ordinal$ =return num$ & "th"
.
.
print "0 to 25:"
for i = 0 to 25
write nth i ordinal$& " "
write ordinal$
write " "
.
print ""
print "250 to 265:"
for i = 250 to 265
write nth i ordinal$& " "
write ordinal$
write " "
.
print ""
print "1000 to 1025:"
for i = 1000 to 1025
write nth i ordinal$& " "
write ordinal$
write " "
.
</syntaxhighlight>
Line 2,294 ⟶ 2,287:
=={{header|Elena}}==
{{trans|C#}}
ELENA 56.0x :
<syntaxhighlight lang="elena">import extensions;
import system'math;
Line 2,304 ⟶ 2,297:
{
int i := self.Absolute;
if (new int[]{11,12,13}.ifExists(i.mod:(100)))
{
^ i.toPrintable() + "th"
Line 2,440 ⟶ 2,433:
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|Fennel}}==
{{trans|Lua}}
 
<syntaxhighlight lang="fennel">
(fn get-suffix [n]
(let [last-two (% n 100)
last-one (% n 10)]
(if (and (> last-two 3) (< last-two 21)) :th
(= last-one 1) :st
(= last-one 2) :nd
(= last-one 3) :rd
:th)))
 
(fn nth [n]
(.. n "'" (get-suffix n)))
 
(for [i 0 25]
(print (nth i) (nth (+ i 250)) (nth (+ i 1000))))
</syntaxhighlight>
 
{{out}}
Same as [[#Lua|Lua]].
 
=={{header|Forth}}==
Line 2,669 ⟶ 2,685:
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013h 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
->
</pre>
 
=={{Header|Insitux}}==
 
<syntaxhighlight lang="insitux">
(function ordinal n
(if ([11 12 13] (rem n 100))
(str n "th")
(str n (or ((rem n 10) ["th" "st" "nd" "rd"]) "th"))))
 
(function line x y
(-> (range x y)
(map (comp ordinal (pad-left " " 6)))
(join " ")))
 
(.. str (line 0 13) "\n" (line 1000 1013)
"\n\n" (line 13 26) "\n" (line 1013 1026)
"\n\n" (line 250 266))
</syntaxhighlight>
 
{{out}}
 
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th
 
13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
 
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
</pre>
 
Line 2,848 ⟶ 2,894:
"1014th", "1015th", "1016th", "1017th", "1018th", "1019th", "1020th",
"1021st", "1022nd", "1023rd", "1024th", "1025th"]]</pre>
 
=={{header|Joy}}==
<syntaxhighlight lang="joy">DEFINE
suffix == abs 89 + 100 rem 9 - 10 rem [{1 2 3} in] [] [pop 0] ifte ["th" "st" "nd" "rd"] of;
nth == ['d 1 1 format] [suffix] cleave concat.
 
[0 250 1000] [25 [dup nth putchars ' putch succ] times nth putchars '\n putch] step.</syntaxhighlight>
{{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 266th 267th 268th 269th 270th 271st 272nd 273rd 274th 275th
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|jq}}==
Line 4,010 ⟶ 4,067:
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|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Show 0 25>
<Show 250 265>
<Show 1000 1025>;
};
 
Nth {
s.N, <Symb s.N>: {
e.X '1' s.Y = e.X '1' s.Y 'th';
e.X '1' = e.X '1st';
e.X '2' = e.X '2nd';
e.X '3' = e.X '3rd';
e.X = e.X 'th';
};
};
 
Cell {
s.N, <First 8 <Nth s.N> ' '>: (e.1) e.2 = e.1;
}
 
Group {
s.N e.1 = <Group (s.N s.N) () e.1>;
(s.N s.M) (e.1) = (e.1);
(s.N 0) (e.1) e.2 = (e.1) <Group (s.N s.N) () e.2>;
(s.N s.M) (e.1) s.2 e.3 = <Group (s.N <- s.M 1>) (e.1 s.2) e.3>;
};
 
Iota {
s.End s.End = s.End;
s.Start s.End = s.Start <Iota <+ s.Start 1> s.End>;
};
 
Each {
s.F = ;
s.F t.I e.X = <Mu s.F t.I> <Each s.F e.X>;
};
 
ShowLine {
(e.Line) = <Prout <Each Cell e.Line>>;
};
 
Show {
s.Start s.End,
<Iota s.Start s.End>: e.Range,
<Group 10 e.Range>: e.Lines
= <Prout <Each ShowLine e.Lines>>;
};</syntaxhighlight>
{{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|REXX}}==
Line 4,262 ⟶ 4,379:
</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program nth;
loop for r in [[0..25], [250..265], [1000..1025]] do
showrange(r);
end loop;
 
proc showrange(r);
i := 0;
loop for s in [nth(n) : n in r] do
putchar(rpad(s, 8));
if (i +:= 1) mod 6 = 0 then print(); end if;
end loop;
print();
end proc;
 
proc nth(n);
sfx := {[1,"st"], [2,"nd"], [3,"rd"]};
return str n +
if n div 10 mod 10 = 1
then "th"
else sfx(n mod 10) ? "th"
end if;
end proc;
end program;</syntaxhighlight>
{{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|Set lang}}==
Due to the language's specification, the input can only contain one character. Therefore, the following code only works with 0-9.
Line 4,442 ⟶ 4,597:
26 | 25th 275th 1025th |
+----------------------------+</pre>
 
=={{header|Stringle}}==
<syntaxhighlight lang="stringle">#i
s "th"
.\#i "1" .:\#i !"1" s "st"
.\#i "2" .:\#i !"1" s "nd"
.\#i "3" .:\#i !"1" s "rd"
$ #i s
i i "."
#i +26 26 +#i #@i 250
#i +266 266 +#i #@i 1000
#i +1026 i ""
#i</syntaxhighlight>
 
=={{header|Swift}}==
Line 4,667 ⟶ 4,835:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for ConvFmt
 
var ranges = [ 0..25, 250..265, 1000..1025 ]
for (r in ranges) {
r.each { |i| SystemFmt.write("%(Conv.ord(i))$r ", i) }
System.print("\n")
}</syntaxhighlight>
2,093

edits