#初始化100張牌 0表示背面 1表示正面
card = [[i,0] for i in range(1,101)]
# print(card)
for j in range(2,101):
jump = j # jump 表示跳過的牌數
pos = j - 1 # pos表示翻動的牌的位置
print(card[pos][1])
while pos < len(card):
card[pos][1] = not card[pos][1] #這一句是關鍵 card[pos][1]初始化爲0 ,而not card[pos][1]就是ture
# print(card)
pos = pos + jump
for card_save in card:
if card_save[1] == 0:
print(card_save[0])
這題不難,關鍵是要想到如何將翻牌這個動作化爲數據語言,
就是這一句:
card[pos][1] = not card[pos][1] #這一句是關鍵 card[pos][1]初始化爲0 ,而not card[pos][1]就是ture