Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -0,0 +1,23 @@
# Compute nCr naively using UHUGEINT
# The caller should ensure 2r < n
create or replace function nCr_(n, r) as
(with recursive cte as
(SELECT 1::UHUGEINT as c, n as numerator, 1::UHUGEINT as m
UNION ALL
SELECT (c * numerator / m) as c,
(numerator - 1) as numerator,
(m + 1) as m
FROM cte
WHERE m <= r)
SELECT last(c order by m)
FROM cte
);
create or replace function nCr(n,r) as (
if( n<r, error('nCr expects r <= n'),
if( 2*r <= n, nCr_(n,r),
nCr_(n, n-r) ) )
);
## Example:
select nCr(140,50);