# 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[0]: #AND OPERATION
20.             invwires = splitTask[0].split(" AND ")
21.             if invwires[0] == "1" and invwires[1] in Wires:
22.                 Wires[targetId] = 1 & Wires[invwires[1]]
23.                 done[i] = True
24.             elif invwires[0] in Wires and invwires[1] in Wires:
25.                 #print "Starting AND OPERATION"
26.                 Wires[targetId] = Wires[invwires[0]] & Wires[invwires[1]]
27.                 done[i] = True
28.         elif "OR" in splitTask[0]: #OR OPERATION
29.             invwires = splitTask[0].split(" OR ")
30.             if invwires[0] in Wires and invwires[1] in Wires:
31.                 #print "Starting OR OPERATION"
32.                 Wires[targetId] = Wires[invwires[0]] | Wires[invwires[1]]
33.                 done[i] = True
35.             lshift = splitTask[0].split(" LSHIFT ")
36.             if lshift[0] in Wires:
37.                 Wires[targetId] = Wires[lshift[0]] << int(lshift[1])
38.                 done[i] = True
40.             rshift = splitTask[0].split(" RSHIFT ")
41.             if rshift[0] in Wires:
42.                 Wires[targetId] = Wires[rshift[0]] >> int(rshift[1])
43.                 done[i] = True
45.             notwire = splitTask[0].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