summaryrefslogtreecommitdiffstats
path: root/19
diff options
context:
space:
mode:
authorGustav Sörnäs <gusso230@student.liu.se>2019-12-20 05:54:43 +0100
committerGustav Sörnäs <gusso230@student.liu.se>2019-12-20 05:54:43 +0100
commit57793988f636a5da0fea1ac2a355c533eb8dde22 (patch)
tree34a71feee2da106b21d1b9621b20f93440c050d1 /19
parent10eae4075ea385e9f31cc517407e740fdc857e70 (diff)
downloadaoc-57793988f636a5da0fea1ac2a355c533eb8dde22.tar.gz
Enable instruction cache
Diffstat (limited to '19')
-rw-r--r--19/py/intcode.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/19/py/intcode.py b/19/py/intcode.py
index 6079250..123f4f3 100644
--- a/19/py/intcode.py
+++ b/19/py/intcode.py
@@ -16,13 +16,13 @@ class Computer(object):
def __init__(self, program):
self.program = program
self.memory_size = len(self.program)
+ self.instruction_cache = {}
self.reset()
def reset(self):
self.memory = self.program.copy()
self.extra_memory = {}
- self.instruction_cache = {}
self.pointer = 0
self.phase_read = False # for day 7
self.relative_base = 0
@@ -37,8 +37,8 @@ class Computer(object):
self.SIG_HALT = False
def parse_op(self, op):
- # if op in self.instruction_cache:
- # return self.instruction_cache[op]
+ if op in self.instruction_cache:
+ return self.instruction_cache[op]
code = op % 100
ops = str(op).zfill(param_amount[code]+2)
self.instruction_cache[op] = [code] + [int(x) for x in ops[:-2][::-1]]