# -*- coding: utf-8 -*-
from itertools import permutations
def math(num1,num2,num3,num4):
'''计算24点'''
sign = ['+','-','*','/']
num = [num1,num2,num3,num4]
order = list(permutations([0,1,2,3],4)) # 进行数字排列
for i in sign:
for j in sign:
for k in sign:
for l in order:
try:
l1 = l[0]
l2 = l[1]
l3 = l[2]
l4 = l[3]
#print(l1,l2,l3,l4)
# 第一种 (a b) (c d)
answer = '(' + str(num[l1]) + i + str(num[l2]) + ')' + j + '(' + str(num[l3]) + k + str(num[l4]) + ')'
if eval(answer) == 24:
print(answer + "=24")
# 第二种 ( ( a b ) c ) d
answer = '(' + '(' + str(num[l1]) + i + str(num[l2]) + ')' + j + str(num[l3]) + ')' + k + str(num[l4])
if eval(answer) == 24:
print(answer + "=24")
# 第三种 (a (b c)) d
answer = '(' + str(num[l1]) + i + '(' + str(num[l2]) + j + str(numl3) + ')' + ')' + k + str(num[l4])
if eval(answer) == 24:
print(answer + "=24")
# 第四种 a ((b c) d)
answer = str(num[l1]) + i + '(' + '(' + str(num[l2]) + j + str(num[l3]) + ')' + k + str(num[l4]) + ')'
if eval(answer) == 24:
print(answer + "=24")
#print(answer + '=' + str(eval(answer)))
# 第五种 a (b (c d))
answer = str(num1) + i + '(' + str(num2) + j + '(' + str(num3) + k + str(num4) + ')' + ')'
if eval(answer) == 24:
print(answer + "=24")
#print(answer + '=' + str(eval(answer)))
except:
pass
a = 4
b = 12
c = 13
d = 10
math(a,b,c,d)