Skip to main content
added 161 characters in body
Source Link
halirutan
  • 113.4k
  • 7
  • 266
  • 479

One way to go through all possible permutations is the NextPermutation function from the Combinatorica` package. But one word of advice: Did you really think through what you are trying to do?

Let's say you just want to loop through 14! iterations and you will do nothing more than to increment a counter and go to the next permutation. ThisIncrementing a counter is one of the most basic operations and it takesshould take almost no time at all. Let's see how far you come in 1 minute:

Needs["Combinatorica`"];

i = 0;
TimeConstrained[Do[i++perm = Range[14];
TimeConstrained[Do[i++; perm = NextPermutation[perm], {14!}], 60]

After this minute, I have finished 0.19%003% (i/14!*100.0) of the 14! iterations. It took a minute iterating over nothing to accomplish 0.19%003%!! Now assume you have a task which needs at least a small amount of time. For instance 1/1000 of a second. With this amount of work per cycle, you will need

14!*1/1000./60/60/24
(* 1009.01 *)

1000 days until you are done. Almost 3 years.

You should probably reconsider the importance of your task. If it is for instance a computation you need for your phd, you will probably run out of money before you have your results.

One way to go through all possible permutations is the NextPermutation function from the Combinatorica` package. But one word of advice: Did you really think through what you are trying to do?

Let's say you just want to loop through 14! iterations and you will do nothing than to increment a counter. This is one of the most basic operations and it takes almost no time at all. Let's see how far you come in 1 minute:

i = 0;
TimeConstrained[Do[i++, {14!}], 60]

After this minute, I have finished 0.19% of the 14! iterations. It took a minute iterating over nothing to accomplish 0.19%!! Now assume you have a task which needs at least a small amount of time. For instance 1/1000 of a second. With this amount of work per cycle, you will need

14!*1/1000./60/60/24
(* 1009.01 *)

1000 days until you are done. Almost 3 years.

You should probably reconsider the importance of your task. If it is for instance a computation you need for your phd, you will probably run out of money before you have your results.

One way to go through all possible permutations is the NextPermutation function from the Combinatorica` package. But one word of advice: Did you really think through what you are trying to do?

Let's say you just want to loop through 14! iterations and you will do nothing more than increment a counter and go to the next permutation. Incrementing a counter is one of the most basic operations and should take almost no time at all. Let's see how far you come in 1 minute:

Needs["Combinatorica`"];

i = 0;
perm = Range[14];
TimeConstrained[Do[i++; perm = NextPermutation[perm], {14!}], 60]

After this minute, I have finished 0.003% (i/14!*100.0) of the 14! iterations. It took a minute iterating over nothing to accomplish 0.003%!! Now assume you have a task which needs at least a small amount of time. For instance 1/1000 of a second. With this amount of work per cycle, you will need

14!*1/1000./60/60/24
(* 1009.01 *)

1000 days until you are done. Almost 3 years.

You should probably reconsider the importance of your task. If it is for instance a computation you need for your phd, you will probably run out of money before you have your results.

Source Link
halirutan
  • 113.4k
  • 7
  • 266
  • 479

One way to go through all possible permutations is the NextPermutation function from the Combinatorica` package. But one word of advice: Did you really think through what you are trying to do?

Let's say you just want to loop through 14! iterations and you will do nothing than to increment a counter. This is one of the most basic operations and it takes almost no time at all. Let's see how far you come in 1 minute:

i = 0;
TimeConstrained[Do[i++, {14!}], 60]

After this minute, I have finished 0.19% of the 14! iterations. It took a minute iterating over nothing to accomplish 0.19%!! Now assume you have a task which needs at least a small amount of time. For instance 1/1000 of a second. With this amount of work per cycle, you will need

14!*1/1000./60/60/24
(* 1009.01 *)

1000 days until you are done. Almost 3 years.

You should probably reconsider the importance of your task. If it is for instance a computation you need for your phd, you will probably run out of money before you have your results.