Go Chocolates By Numbers
func chocolatesByNumbers(n, m int) int {
var gcd func(n, m int) int
gcd = func(n, m int) int {
if n%m == 0 {
return m
}
return gcd(m, n%m)
}
return n / gcd(n, m)
}
This uses the greatest common divisor to figure out how many chocolates get eaten before the pattern repeats.