0

How can I make the following script more intelligent, like a human would do it?

(avoiding the redundant calculations of the full factorials)

def combinations_without_repetition(n, r):
    return (factorial(n) / (factorial(r) * (factorial(n - r))))
combinations_without_repetition(10, 5)

(I get errors: Too large values.)

1
  • Please paste code as code, not as images. Commented Nov 20, 2019 at 15:31

1 Answer 1

1

You can use scipy.special.comb for this. Switching exact to True gives the exact answer as an integer at the cost of speed.

>>> from scipy.special import comb
>>> comb(10, 5, exact=False, repetition=False)
252.0
>>> comb(10, 5, exact=True, repetition=False)
252
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.