猴子吃桃問題

bobo哥發表於2024-03-28

源程式:

day = 10
while True:
m = day
flag = True
for i in range(9):
if m % 2 == 0:
m = m - m//2 - 1
else:
flag = False
break
if m == 1 and flag:
break
day = day + 1
print("第一天桃子的數量是:", day)
for i in range(9):
print(i+1, day, "->", day-day//2-1)
day = day - day//2 - 1

執行結果:

相關文章