Talk:Mind boggling card trick: Difference between revisions

Content added Content deleted
(added some observations and musings on shuffling (nothing to do with lazy walking or tap dancing "Shuffle off to Buffalo).)
Line 5: Line 5:


:: Thanks Gerard. In February 2016 I could not think of a way to turn it into a suitable RC task. The blog post got a fair amount of views however, so I tried again. --[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 07:23, 26 August 2018 (UTC)
:: Thanks Gerard. In February 2016 I could not think of a way to turn it into a suitable RC task. The blog post got a fair amount of views however, so I tried again. --[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 07:23, 26 August 2018 (UTC)

==thoroughness of shuffling the deck==
I found (using the REXX program) that when doing any number of shuffles (including zero), the assertion holds.

I did some digging into my (REXX) code, and found that the creation of a "new" card deck (as it would come out of the manufacturer's box), was flawed.

An almost perfect shuffle was being created by generating a sequence of numbers such that it appeared that there was a red card, a black card, a red card, a black card ...

I rewrote the   '''create'''   subroutine to mimic a new playing card deck     13 spades in order,   13 hearts,   13 clubs,   13 diamonds.

This was a bit of overkill, but now one could divide by   '''4'''   and use the remainder   (same as modulus in this case)   and find which suit the card was:
<br> &nbsp; (0 = spaces, &nbsp; 1 = hearts, &nbsp; 2=clubs, &nbsp; and &nbsp; 3 = diamonds).

The pip could be found out by dividing by &nbsp; '''13''' &nbsp; and adding &nbsp; '''1''', &nbsp; but the pips weren't important for this card trick.

After finding out that it didn't make a difference, I left the new method of creating a new playing deck in, &nbsp; as it didn't hurt, and I would probably need a creation routine to generate a new playing card deck in the future.

Or, of course, you could just divide by &nbsp; '''2''' &nbsp; to test if it was a red or black card &nbsp; &nbsp; red = '''1''' (or odd), &nbsp; black = '''0''' (or even).

Then, I had the REXX program do various number of shuffles, including zero. &nbsp; It didn't matter. &nbsp;

<big>'''All that was necessary was a deck of playing cards that were &nbsp; (exactly) &nbsp; half red, &nbsp; half black'''</big>,
<br>no matter what the order of the playing cards were and no matter how many shuffles (if any) were performed.

The REXX program allows an odd-numbered amount of playing cards, &nbsp; and then the assertion starts failing &nbsp; (with interesting, if not amusing, results).

Even if the shuffled (or not shuffled) card deck 1<sup>st</sup> half was all read, and the 2<sup>nd</sup> half was all black.
<br>By the way, this could produce a situation where one of the "red" or "black" piles had no cards in it, &nbsp; and cause my random swap cards routine to fail when generating a random number from '''1''' to the number of cards, and the REXX '''random''' BIF routine coughed up an error code. &nbsp; I fixed that by testing for a "null" (empty) pile of cards. &nbsp; This won't happen if the playing card deck was already randomized by generating a neat sequence of card (odd/even, odd/even ... repeated, &nbsp; or &nbsp; red/black, red/black, ... &nbsp; repeated).


A single shuffle (as used in the REXX program) exchanged two random cards, &nbsp; two shuffles exchanged four random cards, &nbsp; the shuffle was performed two cards at a time, so it is possible to shuffle a card that was previously shuffled, and in somewhat rare occasion, exchange the same card (that is, no effective shuffle). &nbsp; So, for a very few shuffles, instead of 26 shuffles, maybe 25 were effectively performed. &nbsp; Meh. &nbsp; &nbsp; It wasn't worth the (CPU) time to check for that special case, as the REXX program was performing a hundred thousand simulations at a time, &nbsp; and &nbsp; ''each'' &nbsp; simulation performed &nbsp; (at that time) &nbsp; 26 shuffles. &nbsp; (for the initial program test). &nbsp; I wonder how many electrons I killed for this Rosetta Code task. &nbsp; &nbsp; &nbsp; But no trees were felled, by gum! &nbsp; &nbsp; An atom walked up to another atom and said, "Did you know scientists found out that electrons have mass? &nbsp; "No", said the other, I didn't know they were Catholic!" &nbsp; -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 01:07, 29 August 2018 (UTC)