-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_001.py
More file actions
36 lines (24 loc) · 830 Bytes
/
Copy pathproblem_001.py
File metadata and controls
36 lines (24 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# coding: utf-8
'''
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 multiple_from_list(_list):
def multiple(number):
for multiple in _list:
if number % multiple == 0:
return True
return False
return multiple
def result(number):
return sum(filter(multiple_from_list([3, 5, 6, 9]), range(number)))
# This solution is a tiny bit slower but shorter
# return sum(_ for _ in range(number) if not (number % multiple for multiple in [3, 5, 6, 9]))
def test_problem1():
assert result(10) == 23
def main():
result(1000)
if __name__ == '__main__':
test_problem1()
print(main())
# 233168 in 613 usec