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.
Unless description was changed:
Hey @neerajgopal - thanks for solving and for the kind words and feedback, glad you liked it; and indeed that's a really nice solution!
Btw, since you're interested in combinatorics and timing your solutions, I allow myself to include this link for you:
https://github.com/python/cpython/blob/ffcc7cd57f6a52c6074ecc9f0a9f0177fb1dbfee/Modules/mathmodule.c#L1905
this is how
factorial
is implemented in CPython - it's actually much faster than using the "schoolboy" approach; so if you ever need performance in maths related katas you might need to use the inbuilt one.In Python that's
from math import factorial
.For example on my machine (which is a 10+ year old laptop mind you) the naive factorial takes 7.9 seconds to calculate
100_000!
while the library version takes 4.3 seconds.See you around on other maths katas :)
That's some great early optimisation in your method.
Hey! No worries - rereading my comments, I hope I wasn't too "concise" as I was typing quickly before dinner time :)
Glad you figured out the long integer division stuff, and good luck with advancing on the kata (it's a difficult one in my opinion compared to other 3 kyu, so don't feel bad if you have to come back to it later after solving other number theory katas on Codewars!)
Hi @neerajgopal - no the problem is with your code (the
f(n)
part specifically, if you want a hint)."However each of the numbers is a valid binomial coefficient." <- this claim is incorrect.
Proof - I ran your code and picked the first failed test that I encountered:
916102738276855971 = [916102737627536640, 599982120, 49337211]
<- this is your returned result 3 numbers.Let's look at the first of the 3 values in your returned solution list:
As you can see, the value
916102737627536640
that appears in your result IS NOT a binomial coefficient of the formm choose 2
for some integerm
.It seems you are new to Codewars (welcome!), so please note: in future, please try to make sure there is a real problem with the kata rather than with your solution before raising Issue flag - here as you can see it only takes 2 minutes of checking to see that your claim isn't correct.
This comment is hidden because it contains spoiler information about the solution