http://www.perlmonks.org?node_id=467649


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

I meant my alternative reading of the criteria. That of "No column will end up in the same place". 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.

Indeed, if his Fischer-Yates shuffle is correct, this has to be a possibility in order to meet the fairness criteria. All possible outcomes, including a resultant where the output is in the same ordering as the input have to have equal chance.

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. However, the phraseology of the criteria is such, and the nature of the F_Y shuffle such, that explicitely noting it as a criteria made me consider the possibility that my alternative reading might be the true intent.


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.

Replies are listed 'Best First'.
Re^4: swap columns in a 2-dim array
by polettix (Vicar) on Jun 17, 2005 at 12:26 UTC
    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.

      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.