Created
October 9, 2022 06:14
-
-
Save 136s/e5a89392cf8401788b43f8d5b62025f1 to your computer and use it in GitHub Desktop.
クイズかくれんぼの子・鬼の得点を全探索で計算する(本家: youtu.be/wvw27-wA3Lc )
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
from itertools import product | |
from typing import Tuple | |
def get_total_points(a:int, c:int, d:int, p:float, q:float) -> Tuple[float]: | |
""" | |
クイズかくれんぼの子・鬼の合計得点を全探索で取得する。 | |
Parameters | |
---------- | |
a : int | |
多答クイズの正解数 | |
c : int | |
子の人数 | |
d : int | |
鬼の人数 | |
p : float | |
子の得点(参加者の誰とも重複しなかった場合) | |
q : float | |
鬼の得点(鬼の誰とも重複せずに、かつ、子の誰かと重複した場合) | |
Returns | |
------- | |
pnt_c : int | |
子全員の全通りでの合計得点 | |
pnt_d : int | |
鬼全員の全通りでの合計得点 | |
""" | |
pnt_c, pnt_d = 0, 0 | |
for pat_d in product(range(a), repeat=d): | |
# 鬼間の重複判定 | |
dup_d = [pat_d.count(ans) != 1 for ans in pat_d] | |
for pat_c in product(range(a), repeat=c): | |
# 子の得点計算 | |
for ans in pat_c: | |
if ans not in pat_d: | |
if pat_c.count(ans) == 1: | |
pnt_c += p | |
# 鬼の得点計算 | |
for i, ans in enumerate(pat_d): | |
if not dup_d[i]: | |
if ans in pat_c: | |
pnt_d += q | |
return pnt_c, pnt_d | |
if __name__ == "__main__": | |
a = 28 # 多答クイズの正解数 | |
c, d = 7, 2 # 子・鬼の人数 | |
p, q = 1, 1 # 子・鬼の得点 | |
pnt_c, pnt_d = get_total_points(a, c, d, p, q) | |
print(f"全 {a**(c+d)} 通りでの 1 人あたりの得点の合計\n子: {pnt_c/c}\n鬼: {pnt_d/d}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment