Data update

This commit is contained in:
Ingy döt Net 2025-06-11 20:16:52 -04:00
parent 72eb4943cb
commit 4d5544505c
2347 changed files with 62432 additions and 16731 deletions

View file

@ -0,0 +1,34 @@
int factorial(int n) {
if (n < 1) return 1;
int product = 1;
for (int i = 2; i <= n; ++i) {
product = product * i;
}
return product;
}
int binomial(int n, int k) {
// Special cases
if (k == 0 || k == n) return 1;
if (k < 0 || k > n) return 0;
// For efficiency, we use the smallest value of k or (n-k)
if (k > n - k) k = n - k;
real product = 1;
for (int i = 1; i <= k; ++i) {
product = product * (n - k + i) / i;
}
return round(product);
}
for (int n = 0; n <= 14; ++n) {
for (int k = 0; k <= n; ++k) {
string num = format("%5d", binomial(n, k));
write(stdout, num);
}
write("");
}

View file

@ -0,0 +1,29 @@
for n = 0 to 14
for k = 0 to n
print rjust(binomial(n, k), 5);
next k
print
next n
end
function factorial(n)
if n < 1 then return 1
product = 1
for i = 2 to n
product *= i
next
return product
end function
function binomial(n, k)
if n < 0 or k < 0 or n <= k then return 1
product = 1
for i = n - k + 1 to n
product *= i
next
return int(product / factorial(k))
end function

View file

@ -0,0 +1,23 @@
100 sub factorial(n)
110 if n < 1 then factorial = 1
120 product = 1
130 for i = 2 to n
140 product = product*i
150 next
160 factorial = product
170 end sub
180 sub binomial(n,k)
190 if n < 0 or k < 0 or n <= k then binomial = 1
200 product = 1
210 for i = n-k+1 to n
220 product = product*i
230 next
240 binomial = int(product/factorial(k))
250 end sub
260 for n = 0 to 14
270 for k = 0 to n
280 print using " ####"; binomial(n,k);
290 next k
300 print
310 next n
320 end

View file

@ -0,0 +1,36 @@
Public Sub Main()
For n As Integer = 0 To 14
For k As Integer = 0 To n
Print Format(binomial(n, k), " ####");
Next
Print
Next
End
Function factorial(n As Integer) As Integer
If n < 1 Then Return 1
Dim product As Float = 1 ' Float to avoid overflow
For i As Integer = 2 To n
product *= i
Next
Return product
End Function
Function binomial(n As Integer, k As Integer) As Integer
If n < 0 Or k < 0 Or n <= k Then Return 1
Dim product As Float = 1 ' Float to avoid overflow
For i As Integer = n - k + 1 To n
product *= i
Next
Return Int(product / factorial(k))
End Function

View file

@ -0,0 +1,22 @@
110 FOR N = 0 TO 14
120 FOR K = 0 TO N
130 GOSUB 500 ' Call to binomial
140 PRINT USING " ####"; B;
150 NEXT K
160 PRINT
170 NEXT N
180 END
500 ' Binomial subroutine
510 ' Input: N, K
520 ' Output: B (result of binomial)
530 IF K = 0 OR K = N THEN B = 1: RETURN
540 IF K < 0 OR K > N THEN B = 0: RETURN
550 ' For efficiency, we use the lowest value of K or (N-K)
560 IF K > N-K THEN K1=N-K ELSE K1=K
570 PR = 1
580 FOR I = 1 TO K1
590 PR = PR * (N-K1+I)/I
600 NEXT I
610 B = INT(PR + 0.5)
620 RETURN

View file

@ -0,0 +1,25 @@
10 REM MAIN PROGRAM
20 FOR N = 0 TO 14
30 FOR K = 0 TO N
40 GOSUB 100
50 PRINT B
60 NEXT K
70 PRINT
80 NEXT N
90 GOTO 999
100 REM SUB BINOMIAL
110 IF K = 0 THEN 180
120 IF K = N THEN 180
130 IF K < 0 THEN 190
140 IF K > N THEN 190
150 LET P = 1
160 FOR I = 1 TO K
170 LET P = P * (N-K+I)/I
175 NEXT I
177 LET B = P
178 RETURN
180 LET B = 1
185 RETURN
190 LET B = 0
195 RETURN
999 END

View file

@ -0,0 +1,38 @@
uses console
function factorial(n as integer) as integer
if n < 1 then return 1
single product = 1
int i
for i = 2 to n
product *= i
next
return product
end function
function binomial(n as integer, k as integer) as integer
if n < 0 or k < 0 or n <= k then return 1
single product = 1
int i
for i = n - k + 1 to n
product *= i
next
return product \ factorial(k)
end function
int n, k
for n = 0 to 14
for k = 0 to n
print binomial(n, k) " ";
next k
printl
next n
printl cr "Enter ..."
waitkey

View file

@ -0,0 +1,10 @@
binomial(N, K, 0) :- K > N.
binomial(N, K, X) :- binomial_helper(1, 1, K, N, X).
binomial_helper(R, D, K, _, R) :- D > K, !.
binomial_helper(R, D, K, N, X) :-
D =< K,
R1 is R * N / D,
D1 is D + 1,
N1 is N - 1,
binomial_helper(R1, D1, K, N1, X).

View file

@ -0,0 +1,45 @@
DECLARE FUNCTION factorial! (n AS INTEGER)
DECLARE FUNCTION binomial! (n AS INTEGER, k AS INTEGER)
DIM n AS INTEGER, k AS INTEGER
FOR n = 0 TO 14
FOR k = 0 TO n
PRINT USING " ####"; binomial(n, k);
NEXT k
PRINT
NEXT n
END
FUNCTION binomial! (n AS INTEGER, k AS INTEGER)
' Special cases
IF k = 0 OR k = n THEN binomial = 1
IF k < 0 OR k > n THEN binomial = 0
' For efficiency, we use the smallest value of k or (n-k)
DIM tmp AS INTEGER
tmp = k
IF tmp > n - tmp THEN tmp = n - tmp
DIM product AS DOUBLE ' Double to avoid overflow
product = 1
FOR i = 1 TO tmp
product = product * (n - tmp + i) / i
NEXT i
binomial = product
END FUNCTION
FUNCTION factorial (n AS INTEGER)
IF n <= 1 THEN factorial = 1
DIM product AS DOUBLE ' Double to avoid overflow
product = 1
FOR i = 2 TO n
product = product * i
NEXT i
factorial = product
END FUNCTION

View file

@ -0,0 +1,35 @@
FUNCTION factorial(n)
IF n < 1 THEN LET factorial = 1
LET product = 1
FOR i = 2 TO n
LET product = product*i
NEXT i
LET factorial = product
END FUNCTION
FUNCTION binomial(n, k)
! Special cases
IF k = 0 OR k = n THEN LET binomial = 1
IF k < 0 OR k > n THEN LET binomial = 0
! For efficiency, we use the smallest value of k or (n-k)
IF k > n-k THEN LET k = n-k
LET product = 1
FOR i = 1 TO k
LET product = product*(n-k+i)/i
NEXT i
LET binomial = INT(product+0.5)
END FUNCTION
FOR n = 0 TO 14
FOR k = 0 TO n
PRINT USING " ####": binomial(n,k);
NEXT k
PRINT
NEXT n
END

View file

@ -0,0 +1,25 @@
REM PASCAL'S TRIANGLE
LET N=0
10 LET K=0
20 GOSUB 30
PRINT B," "
LET K=K+1
IF K<=N THEN GOTO 20
PRINT ""
LET N=N+1
IF N<=10 THEN GOTO 10
END
30 REM BINOMIAL
IF K=0 THEN GOTO 50
IF K=N THEN GOTO 50
LET P=1
LET I=1
40 LET T=N-K+I
LET P=P*T/I
LET I=I+1
IF I<=K THEN GOTO 40
LET B=P
RETURN
50 LET B=1
RETURN

View file

@ -0,0 +1,33 @@
for n = 0 to 14
for k = 0 to n
print binomial(n, k) using "####";
next k
print
next n
end
sub factorial(n)
local product, i
if n < 1 return 1
product = 1
for i = 2 to n
product = product * i
next
return product
end sub
sub binomial(n, k)
local product, i
if n < 0 or k < 0 or n <= k return 1
product = 1
for i = n - k + 1 to n
product = product * i
next
return int(product / factorial(k))
end sub