Monday, 18 January 2016

Kata Day 54: Multiples of 3 and 5


Problem Description: 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.

Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in.

Courtesy of ProjectEuler.net

Level:6kyu

Link To Kata: Multiples of 3 and 5

It is the first project euler problem which I encountered at codewars. In this Kata we have to find the sum of all the multiples of 3 or 5 below a given number. We loop from 1 to a number just 1 less than the given number and keep adding the numbers which are factor of either 3 or 5 to a sum variable which we had initialized to 0.

In the end we return the value of sum as the answer to this kata.

Please go through the code for a better understanding. 

Here is the link to code: Kata Day 54

Please mention your suggestions or your doubts in the comment below.

Happy coding. :)

No comments:

Post a Comment