Skip to content

Commit cbdba8d

Browse files
committed
IntCode: added limit of instructions processed
1 parent 13768a8 commit cbdba8d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

2019/IntCode.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ def op_99(self, instr):
175175
self.pointer += self.instr_length["99"]
176176
self.state = "Stopped"
177177

178-
def run(self):
179-
while self.state == "Running":
178+
def run(self, nb_instructions=float("inf")):
179+
i = 0
180+
while self.state == "Running" and i < nb_instructions:
181+
i += 1
180182
opcode_full = self.get_opcode()
181183
opcode = opcode_full[-2:]
182184
self.modes = opcode_full[:-2]

0 commit comments

Comments
 (0)