Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

26
Task/Nth/Ada/nth.adb Normal file
View file

@ -0,0 +1,26 @@
with Ada.Text_IO;
procedure Nth is
function Suffix(N: Natural) return String is
begin
if N mod 10 = 1 and then N mod 100 /= 11 then return "st";
elsif N mod 10 = 2 and then N mod 100 /= 12 then return "nd";
elsif N mod 10 = 3 and then N mod 100 /= 13 then return "rd";
else return "th";
end if;
end Suffix;
procedure Print_Images(From, To: Natural) is
begin
for I in From .. To loop
Ada.Text_IO.Put(Natural'Image(I) & Suffix(I));
end loop;
Ada.Text_IO.New_Line;
end Print_Images;
begin
Print_Images( 0, 25);
Print_Images( 250, 265);
Print_Images(1000, 1025);
end Nth;

View file

@ -13,6 +13,8 @@ static char * get_ordinal(const int i) {
if(i % 100 >= 11 && i % 100 <= 13) ordinal = "th";
else ordinal = i/10==1?"th":i%10==1?"st":i%10==2?"nd":i%10==3?"rd":"th";
sprintf_s(o_number, string_size, "%d%s", i, ordinal);
// Replace the above line with the line below if using clang or gcc:
// sprintf(o_number, "%d%s", i, ordinal);
return o_number;
}

31
Task/Nth/COBOL/nth.cob Normal file
View file

@ -0,0 +1,31 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. NTH-PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NUMBER.
05 N PIC 9(8).
05 LAST-TWO-DIGITS PIC 99.
05 LAST-DIGIT PIC 9.
05 N-TO-OUTPUT PIC Z(7)9.
05 SUFFIX PIC AA.
PROCEDURE DIVISION.
TEST-PARAGRAPH.
PERFORM NTH-PARAGRAPH VARYING N FROM 0 BY 1 UNTIL N IS GREATER THAN 25.
PERFORM NTH-PARAGRAPH VARYING N FROM 250 BY 1 UNTIL N IS GREATER THAN 265.
PERFORM NTH-PARAGRAPH VARYING N FROM 1000 BY 1 UNTIL N IS GREATER THAN 1025.
STOP RUN.
NTH-PARAGRAPH.
MOVE 'TH' TO SUFFIX.
MOVE N (7:2) TO LAST-TWO-DIGITS.
IF LAST-TWO-DIGITS IS LESS THAN 4,
OR LAST-TWO-DIGITS IS GREATER THAN 20,
THEN PERFORM DECISION-PARAGRAPH.
MOVE N TO N-TO-OUTPUT.
DISPLAY N-TO-OUTPUT WITH NO ADVANCING.
DISPLAY SUFFIX WITH NO ADVANCING.
DISPLAY SPACE WITH NO ADVANCING.
DECISION-PARAGRAPH.
MOVE N (8:1) TO LAST-DIGIT.
IF LAST-DIGIT IS EQUAL TO 1 THEN MOVE 'ST' TO SUFFIX.
IF LAST-DIGIT IS EQUAL TO 2 THEN MOVE 'ND' TO SUFFIX.
IF LAST-DIGIT IS EQUAL TO 3 THEN MOVE 'RD' TO SUFFIX.

26
Task/Nth/Euphoria/nth.eu Normal file
View file

@ -0,0 +1,26 @@
function nth(atom n)
sequence suffix
switch remainder(n, 100) do
case 11, 12, 13 then
suffix = "th"
case else
switch remainder(n, 10) do
case 1 then suffix = "st"
case 2 then suffix = "nd"
case 3 then suffix = "rd"
case else suffix = "th"
end switch
end switch
return sprintf("%d%s", {n, suffix})
end function
procedure show_nths(atom start_val, atom end_val)
for i = start_val to end_val do
puts(1, nth(i) & ' ')
end for
puts(1, '\n')
end procedure
show_nths(1, 25)
show_nths(250, 265)
show_nths(1000, 1025)

24
Task/Nth/Gleam/nth.gleam Normal file
View file

@ -0,0 +1,24 @@
import gleam/int
import gleam/io
pub fn main() {
show_nths(from: 0, to: 25)
show_nths(from: 250, to: 265)
show_nths(from: 1000, to: 1025)
}
pub fn nth(n: Int) -> String {
int.to_string(n)
<> case n % 100, n % 10 {
11, _ | 12, _ | 13, _ -> "th"
_, 1 -> "st"
_, 2 -> "nd"
_, 3 -> "rd"
_, _ -> "th"
}
}
fn show_nths(from x: Int, to y: Int) -> Nil {
int.range(x, y, Nil, fn(_, x) { io.print(nth(x) <> " ") })
io.println("")
}

32
Task/Nth/LOLCODE/nth.lol Normal file
View file

@ -0,0 +1,32 @@
HAI 1.3
HOW IZ I NTH YR NUM
MOD OF NUM AN 100, WTF?
OMG 11, OMG 12, OMG 13
FOUND YR "th"
OMGWTF
MOD OF NUM AN 10, WTF?
OMG 1, FOUND YR "st"
OMG 2, FOUND YR "nd"
OMG 3, FOUND YR "rd"
OMGWTF, FOUND YR "th"
OIC
OIC
IF U SAY SO
HOW IZ I SHOW YR START AN YR END
IM IN YR LOOP
VISIBLE START I IZ NTH YR START MKAY " "!
START R SUM OF START AN 1
BOTH SAEM START AN END, O RLY?
YA RLY, GTFO
OIC
IM OUTTA YR LOOP
VISIBLE ""
IF U SAY SO
I IZ SHOW YR 0 AN YR 26 MKAY
I IZ SHOW YR 250 AN YR 266 MKAY
I IZ SHOW YR 1000 AN YR 1026 MKAY
KTHXBYE

View file

@ -0,0 +1,13 @@
lrange(a, b) := makelist(i, i, a, b)$
suffixify(n) := block(
suffixes: ["'st", "'nd", "'rd"],
lastd: mod(n, 10),
last2d: mod(n, 100),
sflag: member(lastd, lrange(1, 3)),
suffix: if sflag and last2d#10+lastd then suffixes[lastd] else "'th",
sconcat(n, suffix)
)$
test_nums: append(lrange(0, 25), lrange(250, 265), lrange(1000, 1025))$
map(suffixify, test_nums);

View file

@ -1,18 +1,16 @@
(phixonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">ordinals</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"th"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"st"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"nd"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"rd"</span><span style="color: #0000FF;">}</span>
constant ordinals = {"th","st","nd","rd"}
<span style="color: #008080;">function</span> <span style="color: #000000;">Nth</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">bool</span> <span style="color: #000000;">apostrophe</span><span style="color: #0000FF;">=</span><span style="color: #004600;">false</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">mod10</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">1</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">mod10</span><span style="color: #0000FF;">></span><span style="color: #000000;">4</span> <span style="color: #008080;">or</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">mod10</span><span style="color: #0000FF;">+</span><span style="color: #000000;">9</span> <span style="color: #008080;">then</span> <span style="color: #000000;">mod10</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">return</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%d%s"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;"><nowiki>'\''</nowiki></span><span style="color: #0000FF;">,</span><span style="color: #000000;">apostrophe</span><span style="color: #0000FF;">)&</span><span style="color: #000000;">ordinals</span><span style="color: #0000FF;">[</span><span style="color: #000000;">mod10</span><span style="color: #0000FF;">]})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
function Nth(integer n, bool apostrophe=false)
integer mod10 = mod(n,10)+1
if mod10>4 or mod(n,100)=mod10+9 then mod10 = 1 end if
return sprintf("%d%s",{n,repeat('\'',apostrophe)&ordinals[mod10]})
end function
<span style="color: #008080;">constant</span> <span style="color: #000000;">ranges</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">25</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">250</span><span style="color: #0000FF;">,</span><span style="color: #000000;">265</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1025</span><span style="color: #0000FF;">}}</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ranges</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">ranges</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">to</span> <span style="color: #000000;">ranges</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">j</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" %6s"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">Nth</span><span style="color: #0000FF;">(</span><span style="color: #000000;">j</span><span style="color: #0000FF;">,</span><span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--
constant ranges = {{0,25},{250,265},{1000,1025}}
for i=1 to length(ranges) do
for j=ranges[i][1] to ranges[i][2] do
if mod(j,10)=0 then puts(1,"\n") end if
printf(1," %6s",{Nth(j,i=2)})
end for
puts(1,"\n")
end for

View file

@ -1,10 +1,8 @@
(phixonline)-->
<span style="color: #008080;">function</span> <span style="color: #000000;">do_one</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">string</span> <span style="color: #000000;">apostrophe</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #7060A8;">pad_head</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%d%s%s"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">apostrophe</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">ord</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)}),</span><span style="color: #000000;">7</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">do_set</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">bool</span> <span style="color: #000000;">bApostrophe</span><span style="color: #0000FF;">=</span><span style="color: #004600;">false</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #000000;">do_one</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'`'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">bApostrophe</span><span style="color: #0000FF;">)}}),</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)&</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #008080;">constant</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">rs</span><span style="color: #0000FF;">,</span><span style="color: #000000;">re</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">({{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">25</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">250</span><span style="color: #0000FF;">,</span><span style="color: #000000;">265</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1025</span><span style="color: #0000FF;">}})</span>
<span style="color: #7060A8;">papply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #000000;">do_set</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">re</span><span style="color: #0000FF;">,</span><span style="color: #000000;">rs</span><span style="color: #0000FF;">}),{</span><span style="color: #004600;">false</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #004600;">false</span><span style="color: #0000FF;">}})</span>
<!--
function do_one(integer n, string apostrophe)
return pad_head(sprintf("%d%s%s",{n,apostrophe,ord(n)}),7)
end function
procedure do_set(sequence s, bool bApostrophe=false)
puts(1,join_by(apply(true,do_one,{s,{repeat('`',bApostrophe)}}),1,10,"")&"\n")
end procedure
constant {rs,re} = columnize({{0,25},{250,265},{1000,1025}})
papply(true,do_set,{apply(true,tagset,{re,rs}),{false,true,false}})

21
Task/Nth/Pluto/nth.pluto Normal file
View file

@ -0,0 +1,21 @@
local fmt = require "fmt"
local ranges = {range(0, 25), range(250, 265), range(1000, 1025)}
print("Without apostrophes:\n")
for ranges as r do
fmt.tprint("%6s", r:mapped(|e| -> fmt.ord(e)), 10)
print()
end
print("With apostrophes:\n")
local function apos(e)
local o = fmt.ord(e)
return o:sub(1, -3) .. "'" .. o:sub(-2)
end
for ranges as r do
fmt.tprint("%7s", r:mapped(|e| -> apos(e)), 10)
print()
end

View file

@ -0,0 +1,21 @@
function nth($inp){
$suffix = "th"
switch($inp % 100){
11{$suffix="th"}
12{$suffix="th"}
13{$suffix="th"}
default{
switch($inp % 10){
1{$suffix="st"}
2{$suffix="nd"}
3{$suffix="rd"}
}
}
}
return "$inp$suffix "
}
0..25 | %{Write-host -nonewline (nth "$_")};""
250..265 | %{Write-host -nonewline (nth "$_")};""
1000..1025 | %{Write-host -nonewline (nth "$_")};""

View file

@ -0,0 +1,23 @@
function Get-Nth ([int]$Number)
{
$suffix = "th"
switch ($Number % 100){
11 {$suffix = "th"}
12 {$suffix = "th"}
13 {$suffix = "th"}
default {
switch ($Number % 10){
1 {$suffix = "st"}
2 {$suffix = "nd"}
3 {$suffix = "rd"}
}
}
}
"$Number$suffix"
}
1..25 | ForEach-Object {Get-Nth $_} | Format-Wide {$_} -Column 5 -Force
251..265 | ForEach-Object {Get-Nth $_} | Format-Wide {$_} -Column 5 -Force
1001..1025 | ForEach-Object {Get-Nth $_} | Format-Wide {$_} -Column 5 -Force

8
Task/Nth/Rye/nth.rye Normal file
View file

@ -0,0 +1,8 @@
nth: fn { n } {
++ either { 11 12 13 } .contains n % 100 { "th" } {
{ "th" "st" "nd" "rd" "th" } -> clamp n % 10 0 4
}
}
[ range 0 25 range 250 265 range 1000 1025 ]
.for { .map ?nth |print }