Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Actually, I (fortunately) do not need two for loops. The main loop of my code is this:
$i = 'A'; # the class label for $n (@temp) { next if defined $arrangements{$n}; # already classified it. @n = split /,/, $n; @classmates = ( $n, join(',', reverse @n) ); # n and its mirror @classmates = (@classmates, &M1(@n)); # Maz 1 @classmates = (@classmates, &M2(@n)); # Maz 2 @classmates = (@classmates, &M3(@n)); # Maz 3 &ClassReunion( $i, \@classmates ); $i++; }

M1, M2, and M3 are the three moves (literally, the permutations represent lines in space) which return a new list of permutations. &ClassReunion just does some magic with the label $i.

M1 is easy, it is just the cyclic permutations of the list Ex: M1(12345) -> 51234, 45123, 34512, 23451. sub M1 { map join(',', @_[$_..$#_], @_[0..$_-1]), 1..$#_ }

M2 is the inverse permutation. The permutation 4132 is equivalent to tr/1234/4132/. The inverse would then be tr/4132/1234/.

sub M2 { my %temp; @temp{(1..@_)} = @_; %temp = reverse %temp; return join(',', @temp{(1..@_)}); }

M3 is, unfortunately much harder to explain, and has much longer code. I've posted a working version of the code on my sratchpad. If you /msg me I will post a better explanation of M3 there as well.

Good Day,
    Dean


If we didn't reinvent the wheel, we wouldn't have rollerblades.


In reply to Re: Re: Re: Big Picture by duelafn
in thread constructing large hashes by duelafn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2023-09-24 21:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?