From 554363ae7cd0c34b3f91d6c2c0a142965419de35 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 8 Dec 2019 18:28:09 +0100 Subject: [PATCH] 2019: d02: ex1: add solution --- 2019/d02/ex1/ex1.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 2019/d02/ex1/ex1.py diff --git a/2019/d02/ex1/ex1.py b/2019/d02/ex1/ex1.py new file mode 100755 index 0000000..98be287 --- /dev/null +++ b/2019/d02/ex1/ex1.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +import sys +from typing import List + + +def run_op(op_codes: List[int]) -> None: + for index in range(0, len(op_codes), 4): # Move every 4 positions + op = op_codes[index] + if op == 99: # Halt + return + if op == 1: # Sum + lhs, rhs, dest = op_codes[index + 1 : index + 4] + op_codes[dest] = op_codes[lhs] + op_codes[rhs] + if op == 2: # Multiplication + lhs, rhs, dest = op_codes[index + 1 : index + 4] + op_codes[dest] = op_codes[lhs] * op_codes[rhs] + + +def main() -> None: + op_codes = [int(n) for n in sys.stdin.read().split(",")] + # Specified modifications + op_codes[1] = 12 + op_codes[2] = 2 + + run_op(op_codes) + + print(op_codes[0]) + + +if __name__ == "__main__": + main()