gamo said:
I don't agree with your simplifications. It needs two hashes:
one for the objective, the circular unique lists,
Why store those in memory? Print them to stdout as you find them (assuming
the first implementation) and read them from disk later. (But in the 2nd
implementation, you naturally save one and only one representation in
memory for each.)
and another
for all the rotations.
If you canonicalize every circular list to have a single canonical
representation, then you only need to test the canonical representation for
one circular-list against all previous canonical representations, not all
the previous rotations. That is what the second one does.
Anyway the problem with lenght 20,
(a a b b b c c c c d d d d d e e e e e e)
is intractable in terms of memory to store the results (using=20
a 16GB RAM computer). I halt the program with 15,4 GB consumed.
The counter of circular lists marks 5,3 millons and running up
at devils speed.
I run your fast routine dpermute to figure out the dimension=20
of the problem, but the program consume many time in the calculation.
=20 Still waiting for coment it.
No need to run it to discover the size. The number of distinct
permutations is 20!/2!/3!/4!/5!/6! which is 97,772,875,200. I don't think
your circular lists can have any internal circular symmetry, so each
underlying circular list should have exactly 20 representatives present,
giving 4,888,643,760 circular lists. (Without any filtering, like your /gg/
example previously.)
If you force one of the 'a's to be in the first slot, then you only need
to generate 9,777,287,520 permutations, getting each circular list twice.
Find the other 'a', and rotate the string to put that 'a' in the first
slot. If the original string is "lt" the new rotated one, print the
original. Otherwise, print nothing as the rotated string either already has
or will later come up in its own right, and get printed at that point.
Nothing needs to be stored in RAM. For speed, I might do it in C, not
Perl.
Xho
--
--------------------
http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.