fork download
  1. # coding:utf-8
  2.  
  3. import random
  4. import collections
  5.  
  6. class CardSet:
  7. NORMAL_ITEMS = ["N", "N", "N", "N", "R", "R", "R", "SR", "SR", "UR"]
  8. BONUS_ITEMS = ["SR", "SR", "SR", "SR", "SR", "SR", "SR", "SR", "SR", "UR"]
  9. PRICES = [200, 210, 220, 230]
  10.  
  11. def __init__(self):
  12. self.shuffle()
  13.  
  14. def set_normalslot(self):
  15. r = random.randrange(10)
  16. return CardSet.NORMAL_ITEMS[r]
  17.  
  18. def set_bonusslot(self):
  19. r = random.randrange(10)
  20. return CardSet.BONUS_ITEMS[r]
  21.  
  22. def shuffle(self):
  23. self.cardset = [self.set_normalslot(), self.set_normalslot(), self.set_normalslot(), self.set_bonusslot()]
  24. random.shuffle(self.cardset)
  25. self.next_slot = 0
  26.  
  27. def get_nextprice(self):
  28. return CardSet.PRICES[self.next_slot]
  29.  
  30. def open(self):
  31. price = self.get_nextprice()
  32. result = self.cardset[self.next_slot]
  33. self.next_slot += 1
  34. if self.next_slot == 4:
  35. self.shuffle()
  36. return price, result
  37.  
  38. def touch_カエデのおっぱい(wallet, shuffling):
  39. # 財布が空になるまでめくる
  40. cardset = CardSet()
  41. results = []
  42. while wallet >= cardset.get_nextprice():
  43. price, result = cardset.open()
  44. results.append(result)
  45. wallet -= price
  46. if shuffling(result):
  47. cardset.shuffle()
  48.  
  49. return results
  50.  
  51. def fullopen_shuffling(result):
  52. # シャッフルしない(全めくり)
  53. return False
  54.  
  55. def SR_shuffling(result):
  56. # SRを見たらシャッフルする
  57. return result == "SR"
  58.  
  59. def SRUR_shuffling(result):
  60. # SRかURを見たらシャッフルする
  61. return result == "SR" or result == "UR"
  62.  
  63. def oneshot_shuffling(result):
  64. # 毎回シャッフルする
  65. return True
  66.  
  67. def main():
  68. MY_WALLET = 10000000
  69.  
  70. fullopen_results = touch_カエデのおっぱい(MY_WALLET, fullopen_shuffling)
  71. SR_results = touch_カエデのおっぱい(MY_WALLET, SR_shuffling)
  72. SRUR_results = touch_カエデのおっぱい(MY_WALLET, SRUR_shuffling)
  73. oneshot_results = touch_カエデのおっぱい(MY_WALLET, oneshot_shuffling)
  74.  
  75. def print_results(results):
  76. dict = {key: val for key, val in collections.Counter(results).items()}
  77. opened = len(results)
  78. print(f"N: {dict['N']}({dict['N'] / opened:.04f}), R: {dict['R']}({dict['R'] / opened:.04f}), SR: {dict['SR']}({dict['SR'] / opened:.04f}), UR: {dict['UR']}({dict['UR'] / opened:.04f}), sum: {opened}")
  79. print()
  80.  
  81. print("fullopen results:")
  82. print_results(fullopen_results)
  83.  
  84. print("SRshuffle results:")
  85. print_results(SR_results)
  86.  
  87. print("SRURshuffle results:")
  88. print_results(SRUR_results)
  89.  
  90. print("oneshot results:")
  91. print_results(oneshot_results)
  92.  
  93. if __name__ == "__main__":
  94. main()
Success #stdin #stdout 1.17s 12996KB
stdin
Standard input is empty
stdout
fullopen results:
N: 13760(0.2958), R: 10435(0.2244), SR: 17594(0.3783), UR: 4722(0.1015), sum: 46511

SRshuffle results:
N: 12507(0.2610), R: 9580(0.1999), SR: 21030(0.4388), UR: 4806(0.1003), sum: 47923

SRURshuffle results:
N: 12767(0.2641), R: 9584(0.1983), SR: 21089(0.4363), UR: 4899(0.1013), sum: 48339

oneshot results:
N: 14971(0.2994), R: 11129(0.2226), SR: 18863(0.3773), UR: 5037(0.1007), sum: 50000