DEV Community

Discussion on: Daily Challenge #82 - English Beggars

Collapse
 
pmkroeker profile image
Peter • Edited

In Go!

amts below could also be a []float64 if required. All posted examples were with ints so that is what I used.

func beggars(amts []int, beggarCount int) []int {
    // defaults to slice of 0's
    sums := make([]int, beggarCount)
    for idx, amt := range amts {
        beggarId := idx % beggarCount
        sums[beggarId] += amt
    }
    return sums
}

Go Playground Example