Mind boggling card trick: Difference between revisions

no edit summary
No edit summary
Line 640:
The number of black cards in the black stack = 4
So the asssertion is correct!
</pre>
 
 
=={{header|Mathematica}}==
 
<lang Mathematica>s = RandomSample@Flatten[{Table[0, 26], Table[1, 26]}]
g = Take[s, {1, -1, 2}]
d = Take[s, {2, -1, 2}]
a = b = {};
Table[If[g[[i]] == 1, AppendTo[a, d[[i]]], AppendTo[b, d[[i]]]], {i,
Length@g}];
a
b
dice = RandomInteger[{1, 6}]
ra = Sort@RandomSample[Range@Length@a, dice]
a = {Delete[a, List /@ ra], a[[ra]]}
rb = Sort@RandomSample[Range@Length@b, dice]
b = {Delete[b, List /@ rb], b[[rb]]}
finala = Join[a[[1]], b[[2]]]
finalb = Join[b[[1]], a[[2]]]
Count[finala, 1] == Count[finalb, 0]</lang>
 
{{output}}
 
<pre>
{1,1,1,0,0,1,0,0,0,1,0,0,0,1,0,1,0,1,1,0,0,1,1,0,1,1,1,1,0,0,0,1,1,0,1,0,1,1,0,0,1,0,1,0,0,1,1,0,0,0,1,1}
{1,1,0,0,0,0,0,0,0,1,0,1,1,1,0,0,1,1,1,0,1,1,0,1,0,1}
{1,0,1,0,1,0,1,1,1,0,1,0,1,1,0,1,0,0,1,0,0,0,1,0,0,1}
{1,0,0,0,1,1,0,0,1,0,0,0,1}
{1,0,1,0,1,1,1,1,0,1,0,1,0}
5
{3,6,9,10,13}
{{1,0,0,1,0,0,0,0},{0,1,1,0,1}}
{1,4,6,8,9}
{{0,1,1,1,1,0,1,0},{1,0,1,1,0}}
{1,0,0,1,0,0,0,0,1,0,1,1,0}
{0,1,1,1,1,0,1,0,0,1,1,0,1}
True
</pre>