Last active
October 1, 2015 05:41
-
-
Save kil9/d27715973b36aef5066f to your computer and use it in GitHub Desktop.
dereste gacha simulator
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
#!/usr/bin/env python3 | |
import sys | |
from functools import reduce | |
# 단차에서 SSR이 나올 확률 | |
P_SSR = 0.015 | |
# 단차에서 SR이나 R이 나올 확률(플래티넘이므로 R 이상 고정) | |
P_SR_R = 1 - P_SSR | |
def combination(n, r): | |
if r==0 or n==r: return 1 | |
# n>>r을 가정한다. | |
multiply = lambda l: reduce(lambda x, y: x*y, l) | |
upper = [x for x in range(n-r+1, n+1)] | |
u = multiply(upper) | |
d = multiply(range(1, r+1)) | |
return int(u/d) | |
# n = 시행횟수 | |
# ssr = n번만큼 시행했을 때 ssr이 나오는 갯수 | |
def gacha(n, ssr): | |
return combination(n, ssr) * P_SSR**ssr * P_SR_R**(n-ssr) | |
def print_table(n): | |
for x in range(n): | |
target_p = gacha(n, x) * 100 | |
if target_p < 1e-10: continue | |
print('{:3d}장: {:3.10f}'.format(x, target_p)) | |
if len(sys.argv) != 2: | |
print('usage: {} [n]') | |
print('n=가챠 시행 수') | |
exit(1) | |
n_gacha = int(sys.argv[1], 10) | |
print('가챠를 {}번 굴렸을 때 SSR이 x장 나올 확률(%)'.format(n_gacha)) | |
print_table(n_gacha) | |
# $ python3 dere.py 60 | |
# 가챠를 60번 굴렸을 때 SSR이 x장 나올 확률(%) | |
# 0장: 40.3806987618 | |
# 1장: 36.8960699346 | |
# 2장: 16.5751380163 | |
# 3장: 4.8799898728 | |
# 4장: 1.0589825739 | |
# 5장: 0.1806183476 | |
# 6장: 0.0252132211 | |
# 7장: 0.0029619593 | |
# 8장: 0.0002988271 | |
# 9장: 0.0000262927 | |
# 10장: 0.0000020420 | |
# 11장: 0.0000001413 | |
# 12장: 0.0000000088 | |
# 13장: 0.0000000005 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment