【发布时间】:2020-01-14 18:06:31
【问题描述】:
在每个玩家从 32 张牌组中获得 5 张牌的扑克中,我试图使用 Mathematica 计算有多少子集恰好包含一对。我创建了一个包含四套花色的套牌,并创建了所有可能的牌组合的子集,现在我尝试使用不同的方法过滤掉所有错误的组合,以排除四类和三类以及满堂彩。但过滤器仍然显示比实际值更高的值。 我的程序的输出是“115584”,但实际结果应该是“107520”。有没有我忘记删除的组合? 这是代码
deck = Sort[Join[Range[7, 14], Range[7, 14], Range[7, 14], Range[7, 14]]]
hand = Subsets[deck, {5}]
SetAttributes[onePair, Orderless]
onePair [{x_, x_, y_, z_, w_} /; x != y != z != w] := True;
Count[hand, _?onePair]
我也试过下面的代码,但输出还是不正确
onePair [{___, x_, x_, ___}] := True; (*we need two cards with same number but different suit*)
onePair [{___, x_, x_, x_, ___}] := False; (*this is to remove three of a kind*)
onePair[{___, x_, x_, y_, y_, ___} /; x != y] := False;(*to exclude the full house probability*)
onePair[{___}] := False;
Count[hand, _?onePair]
【问题讨论】:
标签: set conditional-statements wolfram-mathematica probability poker