package kata func IntegerSum(n int) (sum int) { sum = n * (n+1) / 2 return } func AddMultiples(n int) (sum int) { sum = IntegerSum((n-1)/3) * 3 + IntegerSum((n-1)/5) * 5 - IntegerSum((n-1)/15) * 15 return }
- package kata
func AddMultiples(n int) (sum int) {for i := 1; i < n; i++ {if i % 3 == 0 || i % 5 == 0 {sum += i}}- func IntegerSum(n int) (sum int) {
- sum = n * (n+1) / 2
- return
- }
- func AddMultiples(n int) (sum int) {
- sum = IntegerSum((n-1)/3) * 3 + IntegerSum((n-1)/5) * 5 - IntegerSum((n-1)/15) * 15
- return
- }