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

View file

@ -0,0 +1,27 @@
with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Binomial is
function Binomial (N, K : Natural) return Natural is
Result : Natural := 1;
M : Natural;
begin
if N < K then
raise Constraint_Error;
end if;
if K > N/2 then -- Use symmetry
M := N - K;
else
M := K;
end if;
for I in 1..M loop
Result := Result * (N - M + I) / I;
end loop;
return Result;
end Binomial;
begin
for N in 0..17 loop
for K in 0..N loop
Put (Integer'Image (Binomial (N, K)));
end loop;
New_Line;
end loop;
end Test_Binomial;

View file

@ -1,14 +1,20 @@
function binom(n, k) {
var coeff = 1;
var i;
/**
* Calculates the binomial coefficient n choose k
*
* @param {number} n
* @param {number} k
*/
function nCk(n, k) {
if (k < 0 || k > n) return 0;
if (k < 0 || k > n) return 0;
let result = 1;
for (i = 0; i < k; i++) {
coeff = coeff * (n - i) / (i + 1);
}
for (let i = 0; i < k; i++) {
// `result *= (n - i) / (i + 1)` can cause floating point errors
result = result * (n - i) / (i + 1);
}
return coeff;
return result;
}
console.log(binom(5, 3));
console.log(nCk(5, 3));

View file

@ -0,0 +1,13 @@
HAI 1.3
HOW IZ I BINOMIAL YR N AN YR K
I HAS A RESULT ITZ 1
IM IN YR LOOP UPPIN YR M TIL BOTH SAEM M AN K
RESULT R QUOSHUNT OF PRODUKT OF RESULT AN DIFF OF N AN M AN SUM OF M AN 1
IM OUTTA YR LOOP
FOUND YR RESULT
IF U SAY SO
VISIBLE I IZ BINOMIAL YR 5 AN YR 3 MKAY
KTHXBYE

View file

@ -0,0 +1,13 @@
local int = require "int"
local fmt = require "fmt"
local limit <const> = 14
io.write("n/k |")
for k = 0, limit do fmt.write("%5d", k) end
print()
print("----+" .. string.rep("-----", limit + 1))
for n = 0, limit do
fmt.write("%3d |", n)
for k = 0, n do fmt.write("%5d", int.binomial(n, k)) end
print()
end

View file

@ -0,0 +1,17 @@
function choose($n,$k) {
if($k -le $n -and 0 -le $k) {
$numerator = $denominator = 1
0..($k-1) | foreach{
$numerator *= ($n-$_)
$denominator *= ($_ + 1)
}
$numerator/$denominator
} else {
"$k is greater than $n or lower than 0"
}
}
choose 5 3
choose 2 1
choose 10 10
choose 10 2
choose 10 8

View file

@ -0,0 +1,21 @@
Function binomial(n,k)
binomial = factorial(n)/(factorial(n-k)*factorial(k))
End Function
Function factorial(n)
If n = 0 Then
factorial = 1
Else
For i = n To 1 Step -1
If i = n Then
factorial = n
Else
factorial = factorial * i
End If
Next
End If
End Function
'calling the function
WScript.StdOut.Write "the binomial coefficient of 5 and 3 = " & binomial(5,3)
WScript.StdOut.WriteLine