Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Viniciuscarvalho/6984367d150bd208b553ffb7aa32d835 to your computer and use it in GitHub Desktop.

Select an option

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
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