From 0f81167ad2b90aee5dcb304f40dfc20be4985f88 Mon Sep 17 00:00:00 2001 From: daviddoji Date: Sun, 26 Sep 2021 17:35:28 +0200 Subject: [PATCH] Solution to problem 53 in Julia --- src/Julia/Problem053.jl | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/Julia/Problem053.jl diff --git a/src/Julia/Problem053.jl b/src/Julia/Problem053.jl new file mode 100644 index 0000000..30c5a6c --- /dev/null +++ b/src/Julia/Problem053.jl @@ -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())