I’ve been doing the projecteuler.net coding puzzles. I’m going to blog about my design decisions (I won’t post any actual code nor results, just pseudo code).
#1: Multiples of 3 and 5
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.
Let’s break this problem down into subproblems.
First, we need to iterate through every number less than 1000.
Secondly, we need to check if the number is a multiple of 3 or 5.
Thirdly, if the number is a multiple of 3 or 5 we need to add it to an accumulator.
Finally, we will return the accumulator.
So my solution looks like this:
while i is less than 1000
if i modulo (remainder after division) 3 or 5 equals 0
accumulator + i
return i
This yields the correct answer!
