exercism/go/sum-of-multiples/summultiples.go

28 lines
610 B
Go
Raw Normal View History

2016-08-13 23:20:14 +00:00
package summultiples
// MultipleSummer takes a variable number of ints
// and returns a function that, when given a limit
// returns the sum of the multiples up to that limit
func MultipleSummer(mults ...int) func(int) int {
return func(limit int) int {
var ret int
for i := range mults {
sumMult := mults[i]
for sumMult < limit {
var skip bool
for j := 0; j < i && !skip; j++ {
// Make sure that we haven't already added sumMult
if sumMult%mults[j] == 0 {
skip = true
}
}
if !skip {
ret += sumMult
}
sumMult += mults[i]
}
}
return ret
}
}