Euler 0001
Problem:
Listing all multiples of 3 and 5 under 1000.
Given: 3,5,6,9 are all multiples of 3 and 5 below 10.
Considerations:
We could iterate through every multiple of these numbers but there is going to be overlap when their multiples are divisible by both of them. Such examples would be 15 or 30. In these cases we don't want to add these numbers to the totals twice. This is what we need to watch out for in the code.
Naive approach:
- Keep iterating through all the multiples of 3 and 5
- Add each number to a set, or a list with a not in conditional
- Sum the set or list
target_under = 1000
multiples = [3,5]
found = []
#go through each of our multiples
for multiple in multiples:
#set the running total equal to the first multiple
running_total = multiple
#keep incrementing until we go over the target, then go to the next multiple
while running_total < target_under:
#add the running total to the list if it is not already in it.
if running_total not in found:
found += [running_total]
running_total += multiple