Created
June 10, 2016 11:16
-
-
Save anonymous/307d37d9fbff43f66ef2eee732daa034 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
# options | |
@option_names = ["Small", "Lose a Spin", "Small", "Tiny", "Large", "Lose a Spin", "Small", "Large", "Lose a Spin", "Spin Again"]; | |
def try_spin(s) | |
#puts "trying spin #{s}" | |
result = rand(10) | |
#puts "you scored a #{@option_names[result]}" | |
result | |
end | |
def play_game | |
spin_count = 3 | |
while spin_count > 0 | |
r = try_spin(spin_count) | |
case r | |
when 1,5 | |
spin_count = spin_count - 2 | |
when 4,7 | |
return 'large' | |
when 2,6 | |
return 'small' | |
when 3 | |
return 'tiny' | |
when 9 | |
spin_count = spin_count + 1 | |
else # this will never happen | |
spint_count = spin_count - 1 | |
end | |
end | |
return 'lose' | |
end | |
freq = {'large' => 0, 'small' => 0, 'tiny' => 0, 'lose' => 0} | |
1.upto(1000) do |i| | |
#puts "starting trial #{i}" | |
r = play_game | |
puts r | |
freq[r] += 1 | |
end | |
p freq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment