Trying a simple recursive function that takes a number, splits it in a certain way, and is only supposed to return it if the split numbers are equal to each other.
package main
import "fmt"
func split(sum int) (x, y int) {
x = sum * 4 / 9
y = sum - x
if y == x || sum > 200 {
return
} else {
split(sum+1)
return
}
}
func main() {
fmt.Println(split(10))
}
The output for fmt.Println(split(10))
is 4 and 6
, which is incorrect since they're not equal to each other. Is this due to the return statement t the end of my ELSE statement? I have a JAVA background so I figured that line would never get hit.