Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
euyemura,
combination(k)
returns anEnumerable
, not anArray
of all the combinations. TheEnumerable
is lazy and will only find out the next combination when you call for the next value. When calling anEnumerable
method likereduce
on the return value ofcombination(k)
you canbreak
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 matchest
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.