Unless I am reading his code wrong, it is possible that a given column could be swapped twice and end up in it's original position.
OP uses a shuffled array of 12 different indexes, from which s?he takes six pairs. Each pair contains two different indexes; each index falls into one, and only one, pair; in few words, s?he builds a partitions of the original set into six pairs. Then, s?he performs a single swap using the indexes each pair, which means that each location is read and written exactly once.
I realise that by his original reading, swapping the order of a column twice, so that it ends up back in its original position, meets that criteria.
The OP is also claiming that this is not a homework, so I think that your interpretation is the only possible - that is, an interpretation which looks at the final result and not at useless, noisy intermediate steps.
Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')
Don't fool yourself.
-
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.
|