September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

28
Task/Nth/BaCon/nth.bacon Normal file
View file

@ -0,0 +1,28 @@
' Nth (sans apostrophes)
FUNCTION nth$(NUMBER n) TYPE STRING
LOCAL suffix
IF n < 0 THEN RETURN STR$(n)
IF MOD(n, 100) >= 11 AND MOD(n, 100) <= 13 THEN
suffix = "th"
ELSE
suffix = MID$("thstndrdthththththth", MOD(n, 10) * 2 + 1, 2)
ENDIF
RETURN CONCAT$(STR$(n), suffix)
END FUNCTION
' Test a few ranges
FOR i = 1 TO 4
READ first, last
per = 1
FOR n = first TO last
PRINT nth$(n) FORMAT "%s "
' limit to 10 entries per line
IF per = 10 OR n = last THEN
per = 1
PRINT
ELSE
INCR per
ENDIF
NEXT
NEXT
DATA 0, 25, 250, 265, 1000, 1025, -20, -11

View file

@ -0,0 +1,17 @@
Public Sub Main()
Dim siNums As Short[] = [0, 25, 250, 265, 1000, 1025]
Dim siCount, siNumbers As Short
Dim sOrdinal As String
For siNumbers = 0 To 4 Step 2
For siCount = siNums[siNumbers] To siNums[siNumbers + 1]
sOrdinal = "th"
If Right(Str(siCount), 1) = "1" And Right(Str(siCount), 2) <> "11" Then sOrdinal = "st"
If Right(Str(siCount), 1) = "2" And Right(Str(siCount), 2) <> "12" Then sOrdinal = "nd"
If Right(Str(siCount), 1) = "3" And Right(Str(siCount), 2) <> "13" Then sOrdinal = "rd"
Print siCount & sOrdinal;;
Next
Print gb.NewLine
Next
End

15
Task/Nth/OCaml/nth.ocaml Normal file
View file

@ -0,0 +1,15 @@
let show_nth n =
if (n mod 10 = 1) && (n mod 100 <> 11) then "st"
else if (n mod 10 = 2) && (n mod 100 <> 12) then "nd"
else if (n mod 10 = 3) && (n mod 100 <> 13) then "rd"
else "th"
let () =
let show_ordinals (min, max) =
for i=min to max do
Printf.printf "%d%s " i (show_nth i)
done;
print_newline() in
List.iter show_ordinals [ (0,25); (250,265); (1000,1025) ]

16
Task/Nth/Phix/nth.phix Normal file
View file

@ -0,0 +1,16 @@
constant ordinals = {"th","st","nd","rd"}
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
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,17 +1,13 @@
/*REXX pgm shows ranges of numbers with ordinal (st/nd/rd/th) suffixes.*/
call tell 0, 25 /*show the 1st range of numbers. */
call tell 250, 265 /* " " 2nd " " " */
call tell 1000, 1025 /* " " 3rd " " " */
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────TELL subroutine─────────────────────*/
tell: procedure; parse arg L,H; $= /*get Low & High #s, nullify list*/
do j=L to H /*process the range, low───►high.*/
$=$ j || th(j) /*append the Nth number to list*/
end /*j*/ /* [↑] $ has a leading blank. */
say 'numbers from ' L " to " H ' (inclusive):' /*display the title.*/
say strip($) /*display the list. */
say /*display blank line*/
return /*return to invoker.*/
/*──────────────────────────────────TH subroutine───────────────────────*/
th: procedure; parse arg x; x=abs(x) /*just use ABS value*/
return word('th st nd rd', 1 + x//10 * (x//100%10 \== 1) * (x//10 < 4) )
/*REXX program shows ranges of numbers with ordinal (st/nd/rd/th) suffixes attached.*/
call tell 0, 25 /*display the 1st range of numbers. */
call tell 250, 265 /* " " 2nd " " " */
call tell 1000, 1025 /* " " 3rd " " " */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
tell: procedure; parse arg L,H,,$ /*get the Low and High #s, nullify list*/
do j=L to H; $=$ th(j); end /*process the range, from low ───► high*/
say 'numbers from ' L " to " H ' (inclusive):' /*display the title. */
say strip($); say; say /*display line; 2 sep*/
return /*return to invoker. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
th: parse arg z; x=abs(z); return z||word('th st nd rd',1+x//10*(x//100%10\==1)*(x//10<4))

View file

@ -1,8 +1,8 @@
func nth(n) {
static irregulars = Hash.new(<1 ˢᵗ 2 ⁿᵈ 3 ʳᵈ 11 ᵗʰ 12 ᵗʰ 13 ᵗʰ>...);
n.to_s + (irregulars{n % 100} \\ irregulars{n % 10} \\ 'ᵗʰ');
static irregulars = Hash(<1 ˢᵗ 2 ⁿᵈ 3 ʳᵈ 11 ᵗʰ 12 ᵗʰ 13 ᵗʰ>...)
n.to_s + (irregulars{n % 100} \\ irregulars{n % 10} \\ 'ᵗʰ')
}
[range(0, 25), range(250, 265), range(1000, 1025)].each { |r|
say r.map {|n| nth(n) }.join(" ");
for r in [0..25, 250..265, 1000..1025] {
say r.map {|n| nth(n) }.join(" ")
}

View file

@ -0,0 +1,24 @@
10 FOR N=0 TO 25
20 GOSUB 160
30 PRINT N$;" ";
40 NEXT N
50 PRINT
60 FOR N=250 TO 265
70 GOSUB 160
80 PRINT N$;" ";
90 NEXT N
100 PRINT
110 FOR N=1000 TO 1025
120 GOSUB 160
130 PRINT N$;" ";
140 NEXT N
150 STOP
160 LET N$=STR$ N
170 LET S$="TH"
180 IF LEN N$=1 THEN GOTO 200
190 IF N$(LEN N$-1)="1" THEN GOTO 230
200 IF N$(LEN N$)="1" THEN LET S$="ST"
210 IF N$(LEN N$)="2" THEN LET S$="ND"
220 IF N$(LEN N$)="3" THEN LET S$="RD"
230 LET N$=N$+S$
240 RETURN

View file

@ -0,0 +1,22 @@
10 FOR n=0 TO 25
20 GO SUB 140
30 PRINT n$;" ";
40 NEXT n
50 FOR n=250 TO 265
60 GO SUB 140
70 PRINT n$;" ";
80 NEXT n
90 FOR n=1000 TO 1025
100 GO SUB 140
110 PRINT n$;" ";
120 NEXT n
130 STOP
140 LET s$="th"
150 LET n$=STR$ n
160 IF LEN n$=1 THEN GO TO 180
170 IF n$(LEN n$-1)="1" THEN GO TO 210
180 IF n$(LEN n$)="1" THEN LET s$="st"
190 IF n$(LEN n$)="2" THEN LET s$="nd"
200 IF n$(LEN n$)="3" THEN LET s$="rd"
210 LET n$=n$+s$
220 RETURN

14
Task/Nth/Zkl/nth-1.zkl Normal file
View file

@ -0,0 +1,14 @@
#if 0
fcn addSuffix(n){
z:=n.abs()%100;
if(11<=z<=13) return(String(n,"th"));
z=z%10;
String(n,(z==1 and "st") or (z==2 and "nd") or (z==3 and "rd") or "th");
}
#else
fcn addSuffix(n){
var suffixes=T("th","st","nd","rd","th","th","th","th","th","th"); //0..10
z:=n.abs()%100;
String(n,(z<=10 or z>20) and suffixes[z%10] or "th");
}
#endif

3
Task/Nth/Zkl/nth-2.zkl Normal file
View file

@ -0,0 +1,3 @@
[0..25] .apply(addSuffix).concat(",").println();
[250..265] .apply(addSuffix).concat(",").println();
[1000..1025].apply(addSuffix).concat(",").println();