summaryrefslogtreecommitdiffstats
path: root/19/py/d09.py
diff options
context:
space:
mode:
authorGustav Sörnäs <gusso230@student.liu.se>2019-12-17 20:54:35 +0100
committerGustav Sörnäs <gusso230@student.liu.se>2019-12-17 20:54:35 +0100
commitee96aa7c6ab8f0148e814630e77a726bf61530c0 (patch)
tree444376bc3ecfc235118558cace0de96f3aafd790 /19/py/d09.py
parentca4d3b189da7793ce8744246617c793c8640ce71 (diff)
downloadaoc-ee96aa7c6ab8f0148e814630e77a726bf61530c0.tar.gz
Rename 2019
Diffstat (limited to '19/py/d09.py')
-rw-r--r--19/py/d09.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/19/py/d09.py b/19/py/d09.py
new file mode 100644
index 0000000..ada6763
--- /dev/null
+++ b/19/py/d09.py
@@ -0,0 +1,27 @@
+import intcode
+
+def do(input, code):
+ program = [int(x) for x in input.split(",")]
+ c = intcode.Computer(program)
+ c.input = code
+ output = []
+ while True:
+ c.step()
+ #print(c.relative_base, c.pointer, c.memory)
+ if c.SIG_HALT:
+ break
+ 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__":
+ input = open("../input/09", "r").readlines()
+ print(pt1(input))
+ print(pt2(input))