iKey
iKey

Reputation: 428

Python Faster way to do permutations

I'm trying to do a permutation of 32 items, and I'll pass each permutation into a function to do some calculations on each item in the permutation.

I left it to run for about 6 hours and I cancelled it. Is there a faster way?

Upvotes: 1

Views: 849

Answers (1)

Mark Perryman
Mark Perryman

Reputation: 779

Suppose you could pass 1 billion permutations into your function each second. (N.B. you can't).

Now suppose that you left it running for the age of the universe:

13,700,000,000 (years) times 31,536,000 (seconds in a year)

(1000000000 * 31536000 * 13700000000) / 32! = 0.000000002

You will only be 0.0000002 % of the way through your calculation.

I recommend stopping it now and working out why you needed to do this, and whether you can solve your problem a different way. (If it was just for fun, then maybe pick a smaller number).

Upvotes: 1

Related Questions