47 lines
1.0 KiB
Julia
47 lines
1.0 KiB
Julia
#=
|
|
Created on 26 Sep 2021
|
|
|
|
@author: David Doblas Jiménez
|
|
@email: daviddoji@pm.me
|
|
|
|
Solution for Problem 53 of Project Euler
|
|
https://projecteuler.net/problem=53
|
|
=#
|
|
|
|
using BenchmarkTools
|
|
using Combinatorics
|
|
|
|
function Problem53()
|
|
#=
|
|
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, (5 over 3) = 10.
|
|
|
|
In general, (n over r) = n!/r!*(n-r)!, where r<=n, n!=n*(n-1)*...*2*1, and 0!=1.
|
|
|
|
It is not until
|
|
, that a value exceeds one-million: (23 over 10) = 1144066.
|
|
|
|
How many, not necessarily distinct, values of (n over r) for 1<=n<=100, are greater than one-million?
|
|
=#
|
|
|
|
ans = 0
|
|
for x in 1:100
|
|
for y in 1:100
|
|
if binomial(big(x), y) > 1_000_000
|
|
ans += 1
|
|
end
|
|
end
|
|
end
|
|
|
|
return ans
|
|
end
|
|
|
|
|
|
println("Time to evaluate Problem $(lpad(53, 3, "0")):")
|
|
@btime Problem53()
|
|
println("")
|
|
println("Result for Problem $(lpad(53, 3, "0")): ", Problem53())
|