This is basically fizz buzz but with like 1 or 2 extra steps. Takes all the multiple of 3 and 5 and collect them then output the sum of that collection.
on second thought could have done away with the array by evaluating if it gets summed in the first loop
Alexander Fisher
This is literally the first prompt on projecteuler.net
Carson Morales
this is what I think.
that shit OP create challenge so someone can do his homework, clever joke.
Zachary Ortiz
To be nicer than these guys:
Note that, for instance, getting "the sum of all multiples of 3 up-to-and-including 300" is merely 3 times the sum of 1 to 100. This is because (1+2+3+....+100)*3 = 3+6+9...+300. So we can apply the same logic to the problem.
To get the sum of all multiples of 3 under 1000 (aka less than/equal to 999), you just do the sum of 1 to 333 and multiply by 3. To get the sum of all multiples of 5 under 1000 (again, less than/equal to 999), you do the sum of 1 to 199 and multiply by 5. Programming language division makes this even easier, since 999/5 will round down to 199. And then you subtract the repeats, using 15 as the base.
It requires a Gaussian sort of cleverness to see this the first time you encounter this problem, so you shouldn't feel bad for immediately thinking to use loops.
Ryan Carter
>It requires a Gaussian sort of cleverness Being compared to Gauss is fun and all, but it's pretty fucking far from accurate.
Adam Jackson
"Child Gaussian" would be more accurate, but it's still apt. Unless you work with sums pretty often, there's no reason why you'd easily come up with the trick, especially as this is a programming challenge that seems like a perfect fit for using loops.