summaryrefslogtreecommitdiffstats
path: root/solutions
diff options
context:
space:
mode:
authorGustav Sörnäs <gusso230@student.liu.se>2019-12-09 07:31:33 +0100
committerGustav Sörnäs <gusso230@student.liu.se>2019-12-09 09:19:56 +0100
commit1584228512345750bf187bcb18659a176a5fc2be (patch)
treebd1418dbda40890e12acd6aa5639fa6688e7284c /solutions
parentf79931b49d78b4a1cd9189a3d14dfc426be8f545 (diff)
downloadaoc-1584228512345750bf187bcb18659a176a5fc2be.tar.gz
Add profiling and timing day 9
Diffstat (limited to 'solutions')
-rw-r--r--solutions/py/d09.py38
-rw-r--r--solutions/py/main.py3
2 files changed, 29 insertions, 12 deletions
diff --git a/solutions/py/d09.py b/solutions/py/d09.py
index 5a8f132..3f01cfa 100644
--- a/solutions/py/d09.py
+++ b/solutions/py/d09.py
@@ -1,13 +1,29 @@
import intcode
-input = open("../input/09", "r").readlines()[0]
-
-program = [int(x) for x in input.split(",")]
-c = intcode.Computer(program)
-c.input = 2
-while c.memory[c.pointer] != 99:
- c.step()
- #print(c.relative_base, c.pointer, c.memory)
- if c.output is not None:
- print(c.output)
- c.output = None
+def do(input, code):
+ program = [int(x) for x in input.split(",")]
+ c = intcode.Computer(program)
+ c.input = code
+ output = []
+ while c.memory[c.pointer] != 99:
+ c.step()
+ #print(c.relative_base, c.pointer, c.memory)
+ if c.output is not None:
+ output.append(c.output)
+ c.output = None
+ return output
+
+def pt1(input):
+ return do(input[0], 1)
+
+def pt2(input):
+ return do(input[0], 2)
+
+if __name__ == "__main__":
+ import cProfile
+
+ input = open("../input/09", "r").readlines()
+ print(pt1(input))
+ print(pt2(input))
+ cProfile.run("pt1(input)")
+ cProfile.run("pt2(input)")
diff --git a/solutions/py/main.py b/solutions/py/main.py
index 694c23f..06133f3 100644
--- a/solutions/py/main.py
+++ b/solutions/py/main.py
@@ -8,8 +8,9 @@ import d05
import d06
import d07
import d08
+import d09
-mods = [d01, d02, d03, d04, d05, d06, d07, d08]
+mods = [d01, d02, d03, d04, d05, d06, d07, d08, d09]
timings = [[0 for _ in range(2)] for _ in range(len(mods))]
clock_type = time.CLOCK_MONOTONIC