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.
It's not a bug, it just performance test...
You went over primitive range.
Sorry but your string doesn't throw any exception. I got 38892296835628857864 if you want to create a simple test case. Good luck
@zollipaul159 .. Well ..
You don't technically need any of those things, but the first thing you asked about is useful.
I don't think you're ready for Code Golfing if you're asking such questions ;)
You have to count the number of ways you can take
n-1
elements out ofn
which sum to a given number.So you iterate over the array and for every element, compare the sum of all the other elements with the given number.
Now precompute the sum of all elements and subtract that from both sides of that comparison. And add the given number to both sides. What you're left with is comparing
-element
to-sum+given
. Negate both sides. ( Bothsum
and-given
are inside thereduce
, but you get that part. )How did I do it? Small steps, and some sleeps between them. Inspiration comes slowly to me. :P I iterate on solutions a lot. Over time, you see patterns. There is no substitute for spending the time.
Answer your question?
Inside the function, like this:
Are you sure the argument is 1? Use
print(num)
to see what it is. The error is saying your function returns 1 instead of 2.