On Thu, 28 Sep 2006 03:04:23 +0100, Eric Sosman

<(E-Mail Removed)> wrote:

> Daniel Dyer wrote:

>

>> On Wed, 27 Sep 2006 15:03:01 +0100, gaijinco <(E-Mail Removed)> wrote:

>>

>>> Is there any static methods in Java to do permutations and rotations?

>> http://www.merriampark.com/perm.htm

>> I have modified this (optimised for permutations of length 20 or less)

>> for my own project to provide what I feel is a more useful API:

>

> I find it hard to believe that "optimization" has any useful

> meaning when you're running through all the permutations of twenty

> items.

>

> Do the math: If you use one nanosecond to generate and process

> each permutation, your program needs seventy-seven years to finish.

> What are the chances you will still care about the answer?
That's precisely the point - it's optimised for small sets. 20 just

happens to be the limit imposed by using longs for arithmetic (instead of

BigInteger), the motiviation though was to improve performance when

dealing with sets smaller than that (mostly I've only used permutations of

length 7 or less). Perhaps I'm guilty of premature optimisation but, for

exactly the reason you state, I could not envisage needing to use lengths

greater than 20 so I didn't see a need for the overhead of object

arithmetic.

Perhaps I should have used "restricted" instead of "optimised" since the

point was to draw attention to a restriction in my version that is not

present in the original.

Dan.

--

Daniel Dyer

http://www.dandyer.co.uk