Ad
  • Default User Avatar

    euyemura,
    combination(k) returns an Enumerable, not an Array of all the combinations. The Enumerable is lazy and will only find out the next combination when you call for the next value. When calling an Enumerable method like reduce on the return value of combination(k) you can break out of the loop and return early in you want, hence not wasting cycles. In this kata, I would break out early if my current sum matches t exactly. The solution above does not do this so will always have to sum all combinations so there is a bit of room for performance improvement, but not much.