Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by polettix (Vicar)
on Jun 17, 2005 at 12:26 UTC ( [id://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 (Patriarch) 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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://467676]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-03-19 09:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found