Created
September 27, 2012 11:36
-
-
Save vessi/3793555 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# два игрока бросают кости | |
# первый бросает 20 раз 6-гранный кубик | |
# второй бросает 6 раз 20-гранный кубик | |
# следовательно, у первого при наименее благоприятном исходе сумма очков = 20, при наиболее = 120 | |
# у второго - при наименее благоприятном исходе сумма очков = 6, при наиболее = 120 | |
# код для перебора | |
counter = 0; p1_counter = 0; p2_counter = 0; | |
(20..120).to_a.each do |first_sum| | |
(6..120).to_a.each do |second_sum| | |
counter += 1 | |
p1_counter += 1 if first_sum > second_sum | |
p2_counter += 1 if second_sum > first_sum | |
end | |
end | |
puts "Вероятность победы первого игрока: #{p1_counter * 1.0 / counter}" | |
puts "Вероятность победы второго игрока: #{p2_counter * 1.0 / counter}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment