Ad
  • Custom User Avatar

    Unless description was changed:

    ... between 'left' and 'right' (including both)

  • Default User Avatar

    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 :)

  • Custom User Avatar

    That's some great early optimisation in your method.

  • Default User Avatar

    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!)

  • Default User Avatar

    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:

    res = 916102737627536640
    
    x = 1353589846 # trying various integers to see
    y = 1353589847 # if we can write the above number
    z = 1353589848 # as a binomial coefficient
    
    resx = x*(x+1)//2
    resy = y*(y+1)//2
    resz = z*(z+1)//2
    
    print(resx) # = 916102736273946781 < 916102737627536640
    print(resy) # = 916102737627536628 < 916102737627536640
    print(resz) # = 916102738981126476 > 916102737627536640
    

    As you can see, the value 916102737627536640 that appears in your result IS NOT a binomial coefficient of the form m choose 2 for some integer m.

    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.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution