在尝试使用Ruby进行实验并查看其功能时,我组合了此程序以生成伪造的彩票号码。
我正在尝试生成所有可能的组合,但它似乎不起作用,您能看到我要去哪里了吗?
lotto = [rand(1...50), rand(1...50), rand(1...50), rand(1...50), rand(1...50), rand(1...50)].uniq
lotto_results = lotto.combination(6).cycle.to_a
puts "----START----"
count = 0
lotto_results.each do |x|
count += 1
puts "Comination #{count}: #{x}"
puts "-------------"
end
puts "----FINISH----"
如果要打印所有可能的组合,请执行以下操作:
(1..50).to_a.combination(6).each_with_index do |c, idx|
puts "combination #{idx}: #{c}"
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句