Last active
April 11, 2018 09:07
-
-
Save holysugar/a0f68291b222a9a0922ff75cde6f1031 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
class Calc | |
NUMBER = { | |
n: 16, | |
r: 13, | |
sr: 3, | |
} | |
RATE = { | |
n: 0.79, | |
r: 0.18, | |
sr: 0.03, | |
} | |
def initialize | |
@expected = {} | |
end | |
# [n, r, sr] 枚持っている時に、あと何回引けばコンプできるかの期待値 | |
def expected(n, r, sr) | |
return 0.0 if NUMBER[:n] == n && NUMBER[:r] == r && NUMBER[:sr] == sr | |
# 漸化式 | |
# E(n,r,sr) = 1 | |
# + E(n+1,r,sr) * [n,r,sr]枚持っているときに新しいNを引く確率 ... (1) | |
# + E(n,r+1,sr) * [n,r,sr]枚持っているときに新しいRを引く確率 ... (2) | |
# + E(n,r,sr+1) * [n,r,sr]枚持っているときに新しいSRを引く確率 ... (3) | |
# + E(n,r,sr) * 新しいカードを引かない確率 ... (4) | |
# | |
# を展開する ((4) を左辺に移行し、 1-(新しいカードを引かない確率) , つまり「新しいカードを引く確率」で両辺を割る) | |
@expected[ [n,r,sr] ] ||= ( 1 + | |
( n < NUMBER[:n] ? expected(n + 1, r, sr) * success_rate_in(:n, n) * RATE[:n] : 0 ) + | |
( r < NUMBER[:r] ? expected(n, r + 1, sr) * success_rate_in(:r, r) * RATE[:r] : 0 ) + | |
( sr < NUMBER[:sr] ? expected(n, r, sr + 1) * success_rate_in(:sr, sr) * RATE[:sr] : 0 ) | |
) / success_rate(n, r, sr) | |
end | |
# 新しいカードを引く確率 | |
def success_rate(n, r, sr) | |
success_rate_in(:n, n) * RATE[:n] + | |
success_rate_in(:r, r) * RATE[:r] + | |
success_rate_in(:sr, sr) * RATE[:sr] | |
end | |
# 該当レアリティ内で current_number 枚持っている時に新しいカードを引く確率 | |
def success_rate_in(type, current_number) | |
(NUMBER[type]-current_number).to_f / NUMBER[type] | |
end | |
end | |
x = Calc.new | |
p x.expected(15, 12, 2) | |
p x.expected(0, 0, 0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
画像は https://mathtrain.jp/completegacha