简体   繁体   English

Python进行置换的更快方法

[英]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. 我正在尝试对32个项目进行排列,然后将每个排列传递给函数,以对排列中的每个项目进行一些计算。

I left it to run for about 6 hours and I cancelled it. 我让它运行了大约6个小时,然后取消了它。 Is there a faster way? 有没有更快的方法?

Suppose you could pass 1 billion permutations into your function each second. 假设您每秒可以将10亿个排列传递给函数。 (NB 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. 您将只占整个计算过程的0.0000002%。

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). (如果只是为了好玩,那就选择一个较小的数字)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM