题解 | #24点游戏算法#
def digui(arr,item):
if item < 1:
return False
if len(arr) == 1:
if arr[0] == item:
return True
else:
return False
else:
for i in range(len(arr)):
n = arr[i]
m = arr[0:i] + arr[i + 1:]
if digui(m, item + n) or digui(m, item - n) or digui(m, item / n) or digui(m, item * n):
return True
return False
while True:
try:
arr = list(map(int, input().split()))
re = digui(arr, 24)
if re:
print('true')
else:
print('false')
except:
break