赛尔号超阴间BOSS,让人打到甲亢发作!
10:15
(数学不好,但是暴力美学)

100000次尝试,平均需要每挑战528次成功过关
----------------------------------------------------
这是chatgpt改善后的源代码,希望指正:
import random
import time
def count_ones(num):
count = 0
while num:
count += num & 1
num >>= 1
return count
def one_or_zero(card, xb):
return card ^ (1 << xb)
def simulate_game():
card = 0
n = 0
while count_ones(card) != 9:
n += 1
num = random.randint(1, 3)
if num == 1:
x = random.randint(0, 8)
card = one_or_zero(card, x)
elif num == 2:
x, y = random.sample(range(9), 2)
card = one_or_zero(card, x)
card = one_or_zero(card, y)
elif num == 3:
x, y, z = random.sample(range(9), 3)
card = one_or_zero(card, x)
card = one_or_zero(card, y)
card = one_or_zero(card, z)
return n
start_time = time.time()
n2 = [simulate_game() for _ in range(100000)]
end_time = time.time()
print("耗时: {:.2f}秒".format(end_time - start_time))
test = sum(n2) / len(n2)
print(f"100000次迭代,平均次数{test}")

