Closed kckennylau closed 8 years ago
Not really. This formula can guarantee that if left is integer, then all the intermediate values are integers.
Ah, I see what your intentions were. There are two problems though.
/
is always floating point division in Python 3, even if the result is exact.I forgot to add one to the second argument of range().
@DennisMitchell Is it ok now?
Almost. To match the behavior of the previous code, it should return 0
when the right argument is negative. The case of a negative left argument can be considered undefined behavior for now.
But negative left argument is really defined... They are also useful in binomial expansions.
It is. If you want to implement it correctly, go ahead. I just meant that my code doesn't return anything sensible right now, so there's no reason your code should match its behavior.
Thanks!
Thank you for the contribution!
I made one more functional change to the code, so that nCr(2**256, 2**256-1)
is also computed instantly.
That uses floating point arithmetic, making it inaccurate for large values of n.