File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
project_euler/problem_001 Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ Project Euler Problem 1: https://projecteuler.net/problem=1
3
+
4
+ Multiples of 3 and 5
5
+
6
+ If we list all the natural numbers below 10 that are multiples of 3 or 5,
7
+ we get 3, 5, 6 and 9. The sum of these multiples is 23.
8
+
9
+ Find the sum of all the multiples of 3 or 5 below 1000.
10
+ """
11
+
12
+
13
+ def solution (n : int = 1000 ) -> int :
14
+ """
15
+ Returns the sum of all the multiples of 3 or 5 below n.
16
+
17
+ >>> solution(3)
18
+ 0
19
+ >>> solution(4)
20
+ 3
21
+ >>> solution(10)
22
+ 23
23
+ >>> solution(600)
24
+ 83700
25
+ """
26
+
27
+ result = 0
28
+ for i in range (n ):
29
+ if i % 3 == 0 :
30
+ result += i
31
+ elif i % 5 == 0 :
32
+ result += i
33
+ return result
34
+
35
+
36
+ if __name__ == "__main__" :
37
+ print (f"{ solution () = } " )
You can’t perform that action at this time.
0 commit comments