-
Notifications
You must be signed in to change notification settings - Fork 4
/
nerdle.py
executable file
·96 lines (84 loc) · 2.24 KB
/
nerdle.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python3
import itertools
letters = "0123456789+-*/="
ops = "+-*/"
eq = "="
digit1 = range(1, 10)
digit2 = range(10, 100)
digit3 = range(100, 1000)
digit4 = range(1000, 10000)
def combine(*components):
return list(itertools.product(*components))
def filter1(components):
a = components[0]
op = components[1]
b = components[2]
if op == "+":
l = a + b
elif op == "-":
l = a - b
elif op == "*":
l = a * b
elif op == "/":
l = a / b
return l == components[4]
def filter2(components):
a = components[0]
b = components[2]
c = components[4]
ops = components[1] + components[3]
if ops == "++":
l = a + b + c
elif ops == "+-":
l = a + b - c
elif ops == "+*":
l = a + (b * c)
elif ops == "+/":
l = a + (b / c)
elif ops == "-+":
l = a - b + c
elif ops == "--":
l = a - b - c
elif ops == "-*":
l = a - (b * c)
elif ops == "-/":
l = a - (b / c)
elif ops == "*+":
l = (a * b) + c
elif ops == "*-":
l = (a * b) - c
elif ops == "**":
l = a * b * c
elif ops == "*/":
l = (a * b) / c
elif ops == "/+":
l = (a / b) + c
elif ops == "/-":
l = (a / b) - c
elif ops == "/*":
l = (a / b) * c
elif ops == "//":
l = (a / b) / c
return l == components[6]
equations1 = combine(digit1, ops, digit1, eq, digit4) \
+ combine(digit1, ops, digit2, eq, digit3) \
+ combine(digit1, ops, digit3, eq, digit2) \
+ combine(digit1, ops, digit4, eq, digit1) \
+ combine(digit2, ops, digit1, eq, digit3) \
+ combine(digit2, ops, digit2, eq, digit2) \
+ combine(digit2, ops, digit3, eq, digit1) \
+ combine(digit3, ops, digit1, eq, digit2) \
+ combine(digit3, ops, digit2, eq, digit1) \
+ combine(digit4, ops, digit1, eq, digit1)
equations2 = combine(digit1, ops, digit1, ops, digit1, eq, digit2) \
+ combine(digit1, ops, digit1, ops, digit2, eq, digit1) \
+ combine(digit1, ops, digit2, ops, digit1, eq, digit1) \
+ combine(digit2, ops, digit1, ops, digit1, eq, digit1)
equations1 = list(filter(filter1, equations1))
equations2 = list(filter(filter2, equations2))
for e in equations1:
s = [str(x) for x in e]
print("".join(s))
for e in equations2:
s = [str(x) for x in e]
print("".join(s))