Skip to content

Instantly share code, notes, and snippets.

@takeshy
Created July 3, 2012 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takeshy/3040198 to your computer and use it in GitHub Desktop.
Save takeshy/3040198 to your computer and use it in GitHub Desktop.
10枚中1枚が当たりがある中で、自分で1枚選んで、無作為に他の八枚を開いて当たりが途中で出た時は最初からやり直して、残り2枚になるまで開けた場合
#!/usr/bin/ruby
def init
(1..9).to_a.shuffle
end
success=0
failure=0
10000000.times do
#常に自分が0を選んだこととし、1から9までのランダムな配列の作成
arr = init
#当たり数字を0〜9までの任意とする
bingo = rand(10)
#残りが1個になるまで8個のカードをOPEN
while arr.size > 1
#途中で当たりが出た場合は最初から
break if arr[0] == bingo
arr.shift
end
if arr.size != 1
next
end
if bingo == 0
success+=1
else
failure+=1
end
end
puts "success=#{success} failure=#{failure}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment