Not sure if I should have posted this on math.stackexchange instead, but it includes more programs, so I posted it here.
The question seems very simple, but I sat here for at least an hour without figuring it out. I tried different solutions and read mathematical formulas for it, etc., but this does not give me the correct answer when coding! I made two different decisions for him, and that gives me the wrong answer. The first solution gives me 265334, and the second gives me 232169. The answer is 233168, so the second solution is closer.
I must mention that this is a question from Project Euler, the first one to be exact.
Here is my code. Any ideas what's wrong?
nums = [3, 5] max = 999 result = 0 for num in nums: for i in range(1,max): if num*i < max: result += num*i print result result = 0 for i in range(0,max): if i%3 == 0 or i%5 == 0: result += i print result
qwerty
source share