 AOC - Day 7 Solution

a guest
Dec 7th, 2015
212
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. with open('inputv2.txt') as f:
3.
4. Wires = {}
5. done = list()
6.
7. i = 0
8.
9. for x in range(0,len(inputs)):
10.     done.append(False);
11.
12. while i < len(inputs):
13.     if done[i] == False:
14.
18.
19.         if "AND" in splitTask: #AND OPERATION
20.             invwires = splitTask.split(" AND ")
21.             if invwires == "1" and invwires in Wires:
22.                 Wires[targetId] = 1 & Wires[invwires]
23.                 done[i] = True
24.             elif invwires in Wires and invwires in Wires:
25.                 #print "Starting AND OPERATION"
26.                 Wires[targetId] = Wires[invwires] & Wires[invwires]
27.                 done[i] = True
28.         elif "OR" in splitTask: #OR OPERATION
29.             invwires = splitTask.split(" OR ")
30.             if invwires in Wires and invwires in Wires:
31.                 #print "Starting OR OPERATION"
32.                 Wires[targetId] = Wires[invwires] | Wires[invwires]
33.                 done[i] = True
35.             lshift = splitTask.split(" LSHIFT ")
36.             if lshift in Wires:
37.                 Wires[targetId] = Wires[lshift] << int(lshift)
38.                 done[i] = True
40.             rshift = splitTask.split(" RSHIFT ")
41.             if rshift in Wires:
42.                 Wires[targetId] = Wires[rshift] >> int(rshift)
43.                 done[i] = True
45.             notwire = splitTask.replace("NOT ", "")
46.             if notwire in Wires:
47.                 Wires[targetId] = 65535 - Wires[notwire]
48.                 done[i] = True
49.
50.         else:
51.             try:
53.                 done[i] = True
54.             except ValueError:
57.
58.     if "a" in Wires:
59.         print "FOUND IT!!!! " + str(Wires["a"])
60.         break
61.
62.     elif i+1 == len(inputs):
63.         executed = 0
64.         for x in range(0,len(inputs)):
65.             if done[x] == True:
66.                 executed+=1
67.         print "executed " + str(executed) + " instructions"
68.         i = 0
69.
70.     else:
71.         i+=1
RAW Paste Data