Solution to problem 53 in Julia
This commit is contained in:
parent
609badc011
commit
0f81167ad2
46
src/Julia/Problem053.jl
Normal file
46
src/Julia/Problem053.jl
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#=
|
||||||
|
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 53:")
|
||||||
|
@btime Problem53()
|
||||||
|
println("")
|
||||||
|
println("Result for Problem 53: ", Problem53())
|
Loading…
x
Reference in New Issue
Block a user