I'm trying to simulate the probability of a balanced hand in Bridge (The Theory of Probability by Santosh S. Venkatesh, 2013) using Mathematica. The problem is solved in the textbook but I just wanted to use it to practice writing programs in Mathematica.
The idea is to shuffle the deck, partition it into 4 hands of 13 cards each, and check whether each of the 4 partitions contains an Ace. I'm designating the numbers {1,14,27,40} as the aces (they could have been any 4 different numbers).
uno = Partition[RandomSample[Range[52], 52], 13];
And[
Apply[Or, Map[MemberQ[uno[[1]], #] &, {1, 14, 27, 40}]],
Apply[Or, Map[MemberQ[uno[[2]], #] &, {1, 14, 27, 40}]],
Apply[Or, Map[MemberQ[uno[[3]], #] &, {1, 14, 27, 40}]],
Apply[Or, Map[MemberQ[uno[[4]], #] &, {1, 14, 27, 40}]]
]
I was proud of being able to use Map "MemberQ" to each of the four values {1,14,27,40}.
Where I got stucked is trying to Map it a second time to the four elements of uno.
Position[uno, Alternatives @@ {1, 14, 27, 40}][[All, 1]] == {1, 2, 3, 4}
will give True/False for all 4 hands having an ace... $\endgroup$FreeQ[#, Alternatives @@ {1, 14, 27, 40}, 1] & /@ uno
$\endgroup$