Home > Uncategorized > Rock, Paper, Scissors

Rock, Paper, Scissors

I have been reading “Magical Mathematics”. I admit that I am ignorant of magic and cannot juggle (but would like to learn). I am enjoying getting insights into magic.

This post relates to a rock paper scissors trick on page 185 of the book. In the trick, there is a deck of 27 card with all the triples of choosing (with replacement)  from the {rock, paper, scissors} with object arrange vertically. The trick involves shuffling the cards, putting aside the top card, then taking pairs of the remaining 26 cards and playing rock, paper scissors looking at first, second, the third rows then predicting the removed card. The process is much better explained in the book.

I decided I’d like to implement in Mathematica:
The rock, paper, scissors game:

rps[{"rock", "paper"}] := {"paper", "rock"};
rps[{"paper", "scissors"}] := {"scissors", "paper"}
rps[{"scissors", "rock"}] := {"rock", "scissors"}
rps[{x_, y_}] := rps[{y, x}]
rps[{x_, x_}] := Sequence[];

The round process:

rsub[m_, n_] := Module[{dat, lab = {"rock", "paper", "scissors"}, tl},
dat = rps /@ ((Transpose[#])[[n]] & /@ m);
tl = {#, Count[dat[[All, 2]], #]} & /@ lab;
rps[Select[GatherBy[tl, Mod[#[[2]], 2] &], Length@# == 2 &][[1, All,
1]]][[1]]
]
trick[m_] := {rsub[Partition[Rest@m, 2], #] & /@ Range[3], First@m}

Generating the “cards”:

tup = Tuples[{"rock", "paper", "scissors"}, 3];

Generating 1000 random samples and using thumbnails:

rck = Thumbnail@
Import["http://fc02.deviantart.net/fs71/i/2013/012/f/f/rock_02_png_\
__by_alzstock-d5r85eg.png"];
ppr = Thumbnail@
Import["http://cdn.dickblick.com/items/102/40/10240-1009-1-3ww-l.\
jpg"];
scs = Thumbnail@
Import["http://www.acco.com.au/products/img/Zoom/z9752326%20Marbig%\
20Orange%20Handle%20Scissors%20DEI.jpg"];
rule = Thread[{"rock", "paper", "scissors"} -> {rck, ppr, scs}];
tab = Table[Table[trick[RandomSample[tup, 27]], {10}], {100}];
anim = Grid[
Prepend[{Row[#1 /. rule],
Row[#2 /. rule]} & @@@ #, {"Prediction", "First Card"}],
Frame -> All] & /@ tab;

Exported as animated gif:

rps

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: