Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^4: swap columns in a 2-dim array

by polettix (Vicar)
on Jun 17, 2005 at 12:26 UTC ( #467676=note: print w/replies, xml ) Need Help??

in reply to Re^3: swap columns in a 2-dim array
in thread swap columns in a 2-dim array

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.

Replies are listed 'Best First'.
Re^5: swap columns in a 2-dim array
by BrowserUk (Pope) on Jun 17, 2005 at 13:08 UTC

    You're right. I read the first paragraph, scanned the code, saw the FYS function and coded my offering. I'll post a correction.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://467676]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2018-06-19 12:54 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (114 votes). Check out past polls.