Automatic commit performed through alias...
This commit is contained in:
38
problems/001_problem/001_problem.py
Executable file
38
problems/001_problem/001_problem.py
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Problem 1:
|
||||
#
|
||||
# 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.
|
||||
|
||||
import decorators
|
||||
|
||||
def check_divisibility(num, dict_multiples: dict) -> bool:
|
||||
|
||||
dummy = 1
|
||||
|
||||
for m in dict_multiples:
|
||||
dummy *= num%m
|
||||
if dummy == 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@decorators.function_timer
|
||||
def main():
|
||||
|
||||
multiples = {3,5}
|
||||
sumval = 0
|
||||
|
||||
for n in range(1000):
|
||||
r = check_divisibility(n,multiples)
|
||||
if r:
|
||||
sumval += n
|
||||
|
||||
print(sumval)
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user