euler

git clone git://git.codymlewis.com/euler.git
Log | Files | Refs

commit 89d0d1615d7a9178c8c65563124cd08b168b2cc9
parent 887ba5590d4f91640de061ece58aaddc7337f79e
Author: Cody Lewis <luxdotsugi@gmail.com>
Date:   Sat, 17 Nov 2018 19:35:03 +1100

Solution to problem 1

Diffstat:
AOne.py | 21+++++++++++++++++++++
1 file changed, 21 insertions(+), 0 deletions(-)

diff --git a/One.py b/One.py @@ -0,0 +1,21 @@ +''' +If we list all the natural numbers below 10 that are multiples +of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. + +Find the sum of all the multiples of 3 or 5 below 1000. +''' +def find_sum(multiples, n): + sigma = 0 + for i in range(n): + for m in multiples: + if (i % m) == 0: + sigma += i + break + return sigma + + +if __name__ == "__main__": + MULTIPLES = [3, 5] + LIMIT = 1000 + print(f"The sum of the multiples {MULTIPLES} up to " + + f"{LIMIT} is {find_sum(MULTIPLES, LIMIT)}")