File tree 7 files changed +22
-23
lines changed
7 files changed +22
-23
lines changed Original file line number Diff line number Diff line change 1
1
"""
2
2
Problem Statement:
3
3
If we list all the natural numbers below 10 that are multiples of 3 or 5,
4
- we get 3,5, 6 and 9. The sum of these multiples is 23.
4
+ we get 3, 5, 6 and 9. The sum of these multiples is 23.
5
5
Find the sum of all the multiples of 3 or 5 below N.
6
6
"""
7
7
Original file line number Diff line number Diff line change 1
1
"""
2
2
Problem Statement:
3
3
If we list all the natural numbers below 10 that are multiples of 3 or 5,
4
- we get 3,5, 6 and 9. The sum of these multiples is 23.
4
+ we get 3, 5, 6 and 9. The sum of these multiples is 23.
5
5
Find the sum of all the multiples of 3 or 5 below N.
6
6
"""
7
7
@@ -19,14 +19,14 @@ def solution(n: int = 1000) -> int:
19
19
83700
20
20
"""
21
21
22
- sum = 0
22
+ total = 0
23
23
terms = (n - 1 ) // 3
24
- sum += ((terms ) * (6 + (terms - 1 ) * 3 )) // 2 # sum of an A.P.
24
+ total += ((terms ) * (6 + (terms - 1 ) * 3 )) // 2 # total of an A.P.
25
25
terms = (n - 1 ) // 5
26
- sum += ((terms ) * (10 + (terms - 1 ) * 5 )) // 2
26
+ total += ((terms ) * (10 + (terms - 1 ) * 5 )) // 2
27
27
terms = (n - 1 ) // 15
28
- sum -= ((terms ) * (30 + (terms - 1 ) * 15 )) // 2
29
- return sum
28
+ total -= ((terms ) * (30 + (terms - 1 ) * 15 )) // 2
29
+ return total
30
30
31
31
32
32
if __name__ == "__main__" :
Original file line number Diff line number Diff line change 1
1
"""
2
2
Problem Statement:
3
3
If we list all the natural numbers below 10 that are multiples of 3 or 5,
4
- we get 3,5, 6 and 9. The sum of these multiples is 23.
4
+ we get 3, 5, 6 and 9. The sum of these multiples is 23.
5
5
Find the sum of all the multiples of 3 or 5 below N.
6
6
"""
7
7
@@ -22,38 +22,38 @@ def solution(n: int = 1000) -> int:
22
22
83700
23
23
"""
24
24
25
- sum = 0
25
+ total = 0
26
26
num = 0
27
27
while 1 :
28
28
num += 3
29
29
if num >= n :
30
30
break
31
- sum += num
31
+ total += num
32
32
num += 2
33
33
if num >= n :
34
34
break
35
- sum += num
35
+ total += num
36
36
num += 1
37
37
if num >= n :
38
38
break
39
- sum += num
39
+ total += num
40
40
num += 3
41
41
if num >= n :
42
42
break
43
- sum += num
43
+ total += num
44
44
num += 1
45
45
if num >= n :
46
46
break
47
- sum += num
47
+ total += num
48
48
num += 2
49
49
if num >= n :
50
50
break
51
- sum += num
51
+ total += num
52
52
num += 3
53
53
if num >= n :
54
54
break
55
- sum += num
56
- return sum
55
+ total += num
56
+ return total
57
57
58
58
59
59
if __name__ == "__main__" :
Original file line number Diff line number Diff line change 1
1
"""
2
2
Problem Statement:
3
3
If we list all the natural numbers below 10 that are multiples of 3 or 5,
4
- we get 3,5, 6 and 9. The sum of these multiples is 23.
4
+ we get 3, 5, 6 and 9. The sum of these multiples is 23.
5
5
Find the sum of all the multiples of 3 or 5 below N.
6
6
"""
7
7
Original file line number Diff line number Diff line change 1
1
"""
2
2
Problem Statement:
3
3
If we list all the natural numbers below 10 that are multiples of 3 or 5,
4
- we get 3,5, 6 and 9. The sum of these multiples is 23.
4
+ we get 3, 5, 6 and 9. The sum of these multiples is 23.
5
5
Find the sum of all the multiples of 3 or 5 below N.
6
6
"""
7
7
8
- """A straightforward pythonic solution using list comprehension"""
9
-
10
8
11
9
def solution (n : int = 1000 ) -> int :
12
10
"""Returns the sum of all the multiples of 3 or 5 below n.
11
+ A straightforward pythonic solution using list comprehension.
13
12
14
13
>>> solution(3)
15
14
0
Original file line number Diff line number Diff line change 1
1
"""
2
2
Problem Statement:
3
3
If we list all the natural numbers below 10 that are multiples of 3 or 5,
4
- we get 3,5, 6 and 9. The sum of these multiples is 23.
4
+ we get 3, 5, 6 and 9. The sum of these multiples is 23.
5
5
Find the sum of all the multiples of 3 or 5 below N.
6
6
"""
7
7
Original file line number Diff line number Diff line change 1
1
"""
2
2
Problem Statement:
3
3
If we list all the natural numbers below 10 that are multiples of 3 or 5,
4
- we get 3,5, 6 and 9. The sum of these multiples is 23.
4
+ we get 3, 5, 6 and 9. The sum of these multiples is 23.
5
5
Find the sum of all the multiples of 3 or 5 below N.
6
6
"""
7
7
You can’t perform that action at this time.
0 commit comments