一千美元的故事(钱放入信封中)
def dollar(n):
global story_money
money = []
for i in range(10):
if 2**(i+1) > story_money-sum(money):
money.append(story_money-2**i+1)
break
money.append(2 ** i)
# print(money)
answer = []
if n >= money[-1]:
answer.append(10)
n -= money[-1]
n = list(bin(n))[2:]
n.reverse()
rank = 1
for i in n:
if i == '1':
answer.append(rank)
rank += 1
print(answer)
story_money = 1000
dollar(500)
2020-05-29
本文来自博客园,作者:CodeYaSuo,转载请注明原文链接:https://www.cnblogs.com/hany-postq473111315/p/12989353.html