func solvable2(res int, ins []int) bool { n, ins := ins[len(ins)-1], ins[:len(ins)-1] if len(ins) == 0 { return res == n } if solvable2(res-n, ins) { return true } if res%n == 0 && solvable2(res/n, ins) { return true } d := digits(n) p := pow10(d) return res%p == n && solvable2(res/p, ins) } func digits(n int) int { var d int = 1 for n > 10 { d++ n /= 10 } return d } func pow10(n int) int { var p int = 1 for ; n > 0; n-- { p *= 10 } return p }