Last active
January 9, 2019 00:40
-
-
Save Viniciuscarvalho/6984367d150bd208b553ffb7aa32d835 to your computer and use it in GitHub Desktop.
Code Kata - Kyu 7 - sum-of-all-the-multiples-of-3-or-5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Description: | |
| Your task is to write function findSum. | |
| Upto and including n, this function will return the sum of all multiples of 3 and 5. | |
| For example: | |
| findSum(5) should return 8 (3 + 5) | |
| findSum(10) should return 33 (3 + 5 + 6 + 9 + 10) | |
| -------------------------------------------------- | |
| func findSum(_ n: Int) -> Int { | |
| var sum = 0 | |
| // loop over the entire range | |
| for i in 0...n { | |
| // Whenever a multiple of 3 or 5 is found, add it to our placeholder | |
| if i%3 == 0 || i%5 == 0 { | |
| sum += i | |
| } | |
| } | |
| return sum | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment