Programming Mythbusters - Shuffling part 2
I'm back with a part 2 to my Programming Mythbusters! - Can You Unshuffle a Deck of Cards?. If you haven't read it, please start there.
Image from Flickr.com
I realized my results were a little sloppy at the end. I was trying to find a trend of 4 or more cards in order (in either direction), but I was clearing it out each time it changed direction. This returned zero results almost every time.
To resolve this issue, I added in a new variable in my CardTrend function called
maxTrend. Whenever a trend ends, if the current trend length is longer than maxTrend, then maxTrend gets that value. Then reset trend back to 1.
if (trend > maxTrend) maxTrend = trend; trend = 1;
Now I'm getting trend results. After a couple sets of 50,000 shuffles, I got a nice result.
Here you can see several trends after the first shuffle, but then not a one until over 23,000 shuffles go by. Then not again until the 40,000's where we have 3 shuffles quite close together with trends. I highlighted the trends in yellow for easier finding.
The Result (again)
This doesn't change my previous verdict. In fact, I think it nudges it closer to busted, but still technically plausible. You would have to really work at it to do it, but I guess it could be done. But for 99% of us, I seriously doubt it's even possible to get this good of a result, let alone that many shuffles in...
Thanks for reading my follow-up. If you have any other weird ideas that could be possibly tested with code, let me know! I'll see if I can bust that myth!