-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp677.py
71 lines (57 loc) · 2.08 KB
/
p677.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
# ARQ
# (red(3), blue(2), white(1), yellow(2 not yellow), light yellow(1 not yellow))
from pprint import pprint
from collections import defaultdict
g2 = {(2, 0, 0, 0, 0): 1, # red red
(1, 1, 0, 0, 0): 1, # red blue
(1, 0, 0, 1, 0): 1, # red yellow
(0, 2, 0, 0, 0): 1, # blue blue
(0, 1, 0, 1, 0): 1} # blue yellow
pprint(g2)
def next_step(gs):
g3 = defaultdict(lambda:0)
for g,k in gs.items():
cr,cb,cw,cy,cly = g
# USING RED NODE
if cr > 0:
# adding red node to red node
g3[(cr,cb+1,cw,cy,cly)] = 1
# adding blue node to red node
g3[(cr - 1, cb + 2, cw, cy, cly)] = 1
# adding yellow node to red node
g3[(cr - 1, cb + 1, cw, cy + 1, cly)] = 1
# USING BLUE NODE
if cb > 0:
# adding red node to blue node
g3[(cr + 1, cb - 1, cw + 1, cy, cly)] = 1
# adding blue node to blue node
g3[(cr, cb, cw + 1, cy, cly)] = 1
# adding yellow node to blue node
g3[(cr, cb - 1, cw + 1, cy + 1, cly)] = 1
# USING WHITE NODE
if cw > 0:
# adding red node to white node
g3[(cr + 1, cb, cw - 1, cy, cly)] = 1
# adding blue node to white node
g3[(cr, cb + 1, cw - 1, cy, cly)] = 1
# adding yellow node to white node
g3[(cr, cb, cw - 1, cy + 1, cly)] = 1
# USING YELLOW NODE
if cy > 0:
# adding red node to yellow node
g3[(cr + 1, cb, cw, cy - 1, cly + 1)] = 1
# adding blue node to yellow node
g3[(cr, cb + 1, cw, cy - 1, cly + 1)] = 1
# USING LIGHT YELLOW NODE
if cly > 0:
# adding red node to light yellow node
g3[(cr + 1, cb, cw, cy, cly-1)] = 1
# adding blue node to light yellow node
g3[(cr, cb + 1, cw, cy, cly - 1)] = 1
return g3
g3 = next_step(g2)
pprint(dict(g3))
print(sum(v for k,v in g3.items()))
g4 = next_step(g3)
pprint(dict(g4))
print(sum(v for k, v in g4.items()))