/*
Project Euler #53 in Picat.
https://projecteuler.net/problem=53
"""
Combinatoric selections
There are exactly ten ways of selecting three from five, 12345:
123, 124, 125, 134, 135, 145, 234, 235, 245, and 345
In combinatorics, we use the notation, 5C3 = 10.
In general,
nCr = n! / r!(n−r)!
where r <= n, n! = n*×*(n−1) ×... × 3 × 2 × 1, and 0! = 1.
It is not until n = 23, that a value exceeds one-million: 23 C 10 = 1144066.
How many, not necessarily distinct, values of nCr, for 1 <= n <= 100, are
greater than one-million?
"""
This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com
See also my Picat page: http://www.hakank.org/picat/
*/
% import util.
% import cp.
main => euler53.
% 0.024s
euler53 =>
println(length([1 : N in 1..100, I in 1..N, binomial(N,I) > 1_000_000])).
% 0.024s
euler53b =>
println([[B : I in 1..N, B = binomial(N,I), B > 1_000_000 ] : N in 1..100].flatten().length).
% 0.03s
euler53c =>
G = [],
foreach(N in 1..100)
G2 = [B : I in 1..N, B = binomial(N,I), B > 1_000_000 ],
G := G ++ G2
end,
println(g=G.length),
nl.
table
binomial(N,K) = Res =>
R = 1,
foreach(I in 1..K)
R := floor(R * ((N-I+1)/I))
end,
Res = R.