djb*_*ick 1 ruby poker combinations
例如,52张牌的扑克牌中的5张牌= 2598960种组合.
我怎么会实际显示所有这些组合?
查找号码的代码很简单:
def binomial_coef(total,subset)
factorial(total) / (factorial(subset) * factorial(total - subset))
end
def factorial(n)
n.downto(1).inject(:*)
end
# different 5 card poker hand combinations
cards = 52
hand_number = 5
puts binomial_coef(cards, hand_number)
Run Code Online (Sandbox Code Playgroud)
有关打印出所有实际组合的解决方案的任何想法?
例如:
1,2,3,4,5
1,2,3,4,6
等
甚至帮助开始.谢谢!
cards = (1..52).to_a
hand_number = 5
cards.combination(hand_number).to_a
=> [[1,2,3,4,5],[1,2,3,4,6],...]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
409 次 |
| 最近记录: |