Problem 1
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.
Solution
— I have a table called Number
— that has about 3 million
— integers starting at 1
— this problem is pretty
— simple from a query perspective
SELECT SUM(number) FROM Number
WHERE number < 1000
AND ((number % 3 = 0) OR (number % 5 = 0))
Discussion
When it’s possible to fill a table in a reasonable amount of time using brute force techniques, I will. If the technique for filling the table is interesting I will demonstrate that. I realize that in many cases this won’t be possible so I will have to use whatever “trick” is required to solve the problem before the sun burns out.
If you have questions, leave a comment or find me on Twitter (@azzlsoft) or email (rich@azzlsoft.com).