Returns the sum of all the multiples of 3 or 5 below n. >>> solution(3) 0 >>> solution(4) 3 >>> solution(10) 23 >>> solution(600) 83700
(n: int = 1000)
| 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 | xmulti = [] |
| 28 | zmulti = [] |
| 29 | z = 3 |
| 30 | x = 5 |
| 31 | temp = 1 |
| 32 | while True: |
| 33 | result = z * temp |
| 34 | if result < n: |
| 35 | zmulti.append(result) |
| 36 | temp += 1 |
| 37 | else: |
| 38 | temp = 1 |
| 39 | break |
| 40 | while True: |
| 41 | result = x * temp |
| 42 | if result < n: |
| 43 | xmulti.append(result) |
| 44 | temp += 1 |
| 45 | else: |
| 46 | break |
| 47 | collection = list(set(xmulti + zmulti)) |
| 48 | return sum(collection) |
| 49 | |
| 50 | |
| 51 | if __name__ == "__main__": |