-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuzzle_08_b2.py
45 lines (38 loc) · 922 Bytes
/
puzzle_08_b2.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
import sys
import re
lines = []
for line in sys.stdin:
line = line.rstrip()
lines.append(line)
print lines
def try_this():
acc = 0
visited = {}
j = 0
while j < len(lines):
(instruction,arg) = lines[j].split(' ')
if visited.has_key(str(j)):
print "Not this",acc
return
visited[str(j)] = 1
if instruction == 'nop':
j +=1
if instruction == 'jmp':
j += int(arg)
if instruction == 'acc':
acc += int(arg)
j +=1
if j == len(lines):
print "Found", acc
exit()
for i in range(len(lines)):
cpy = lines[i]
(instruction,arg) = lines[i].split(' ')
if instruction == 'nop':
lines[i] = 'jmp '+ arg
try_this()
lines[i] = cpy
if instruction == 'jmp':
lines[i] = 'nop '+ arg
try_this()
lines[i] = cpy