-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuzzle_08_b.py
44 lines (39 loc) · 1.01 KB
/
puzzle_08_b.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
import sys
def try_this():
index = 0
acc = 0
visited = {}
while index < len(lines):
(instruction, arg) = lines[index].split(' ')
#print instruction, arg
if visited.has_key(index):
print "Not this",acc
return
visited[index] = 1
if instruction == 'nop':
index +=1
if instruction == 'acc':
acc += int(arg)
index +=1
if instruction == 'jmp':
index += int(arg)
if index == len(lines):
print "Found :",acc
lines = []
for line in sys.stdin:
line = line.strip()
lines.append(line)
for i in range(len(lines)):
copy = lines[i]
(instruction, arg) = lines[i].split(' ')
print lines[i]
if instruction == 'nop':
lines[i] = 'jmp '+ arg
print i, " changing..............", lines[i], "="
try_this()
lines[i]= copy
if instruction == 'jmp':
lines[i] = 'nop '+ arg
print i, " changing.........", lines[i], "="
try_this()
lines[i]= copy