I ~~like~~ love working with algorithms.

**Concept**: 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.

**Test**: Find the sum of all the multiples of 3 or 5 below 1000.

**A solution** I came up with in swift to sum multiples of any Int and also have an under param to test for multiples below 1000 in this case.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
func sumMultiple(of: Int, under: Int) { var i = 0 var multiple = 0 var sum = 0 while multiple < under { sum += multiple i += 1 multiple = i * of } print("The sum of the multiples of \(of) below \(under) is \(sum)") } sumMultiple(of: 3, under: 1000) |

Console output: The sum of the multiples of 3 below 1000 is 166833