Say I have a deck of 52 cards. I now remove two cards from the deck, say it is Diamond 2 and 4. I now create a subset {5} meaning I print every 5 card combination of the 50 cards I have left.
How do I now add back both the diamond 2 and 4 into each subset i.e. each set of 5 card combinations?
Update Use resource function PlayingCardGraphic
to generate graphic
Converting to the right format is a bit messy, would have been easier if the ranks were generated in a different way.
newHands =
Subsets[deckPart, {5}] // Map[Join[#, cardsToRemove] & /* RandomSample];
hand = newHands // RandomChoice
(hand //
Map[StringSplit[#,
x : DigitCharacter .. | {"J", "Q", "K", "A"} :> x] &]) /. {v_,
s_} :> {If[MemberQ[{"J", "Q", "K", "A"}, v], v, ToExpression@v],
s} //
ResourceFunction["PlayingCardGraphic"][#, "CardSpreadAngle" -> .8] &
The number of 5 card subsets is
50!/(5! 45! = 2118760
it takes ~2.8s to compute and ~10s to display in the notebook on my machine.
suits = ToString /@ {\[SpadeSuit], \[HeartSuit], \[DiamondSuit], \[ClubSuit]}
ranks = CharacterRange["2", "9"]~Join~{"10", "J", "Q", "K", "A"}
deck = Outer[StringJoin, ranks, suits] // Flatten // RandomSample
cardsToRemove = {"2\[DiamondSuit]", "4\[DiamondSuit]"}
deckPart = deck // DeleteCases[Alternatives @@ cardsToRemove]
Subsets[deckPart, {5}] // Map[Join[#, cardsToRemove] & /* RandomSample]