-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheval24.py
56 lines (44 loc) · 1.43 KB
/
eval24.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import itertools
symbols = ["+","-","*","/"]
symbols_plus = ["+","*","/"]
symbols_minus = ["-","*","/"]
brackets = ["(",")"]
integers = [1, 2, 3, 4]
pm = map(lambda x: ["-"] + list(x), list(itertools.permutations(symbols_plus)))
pp = map(lambda x: ["+"] + list(x), list(itertools.permutations(symbols_minus)))
perm_symbols = pp + pm
print perm_symbols
result = []
for sym_arr in perm_symbols:
for repm_int in itertools.permutations(integers):
perm = ""
for i in range(4):
perm += sym_arr[i] + str(repm_int[i])
result.append(perm)
print result
def get_permut(integers):
symbols_plus = ["+", "*", "/"]
symbols_minus = ["-", "*", "/"]
# brackets = ["(", ")"]
# integers = [1, 2, 3, 4]
pm = map(lambda x: ["-"] + list(x),
list(itertools.permutations(symbols_plus)))
pp = map(lambda x: ["+"] + list(x),
list(itertools.permutations(symbols_minus)))
perm_symbols = pp + pm
# print perm_symbols
result = []
for sym_arr in perm_symbols:
for repm_int in itertools.permutations(integers):
perm = ""
for i in range(4):
perm += sym_arr[i] + str(repm_int[i])
result.append(perm)
return result
def get_statement(integers, target):
perms = get_permut(integers)
for i in perms:
exec "x=" + i
if x == target:
return i + " = " + str(x)
get_statement([2,3,5,11], 24)