David Doblas Jiménez 86aff084d8 Clean-up
2021-09-20 18:08:16 +02:00

46 lines
1.0 KiB
Julia
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#=
Created on 27 Aug 2021
@author: David Doblas Jiménez
@email: daviddoji@pm.me
Solution for Problem 31 of Project Euler
https://projecteuler.net/problem=31
=#
using BenchmarkTools
using IterTools
function Problem31()
#=
In the United Kingdom the currency is made up of pound (£) and pence (p).
There are eight coins in general circulation:
1p, 2p, 5p, 10p, 20p, 50p, £1 (100p), and £2 (200p).
It is possible to make £2 in the following way:
1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
How many different ways can £2 be made using any number of coins?
=#
no_ways = 0
coins = [2, 5, 10, 20, 50, 100]
bunch_of_coins = product([0:i:200 for i in coins]...)
for money in bunch_of_coins
if sum(money) <= 200
no_ways += 1
end
end
# consider also the case for 200 coins of 1p
return no_ways + 1
end
println("Time to evaluate Problem 31:")
@btime Problem31()
println("")
println("Result for Problem 31: ", Problem31())