From 61ae887bbcfe5d7403fbea4336b85d6ed8107376 Mon Sep 17 00:00:00 2001 From: flifloo Date: Mon, 2 Dec 2019 09:33:27 +0100 Subject: [PATCH] Day 2 P2 --- 2019/day 2/P2/computer.py | 24 ++++++++++++++++++++++++ 2019/day 2/P2/input.txt | 1 + 2 files changed, 25 insertions(+) create mode 100644 2019/day 2/P2/computer.py create mode 100644 2019/day 2/P2/input.txt diff --git a/2019/day 2/P2/computer.py b/2019/day 2/P2/computer.py new file mode 100644 index 0000000..54a6d1c --- /dev/null +++ b/2019/day 2/P2/computer.py @@ -0,0 +1,24 @@ +codes = open("input.txt").read().split(",") +noun = -1 +verb = -1 +while noun <= 99: + noun+=1 + verb=-1 + while verb <= 99: + verb+=1 + codes = open("input.txt").read().split(",") + codes = [int(i) for i in codes] + + codes[1] = noun + codes[2] = verb + + i=0 + while codes[i+3] < len(codes) and codes[i] != 99: + if codes[i] == 1: + codes[codes[i+3]] = codes[codes[i+1]] + codes[codes[i+2]] + elif codes[i] == 2: + codes[codes[i+3]] = codes[codes[i+1]] * codes[codes[i+2]] + i+=4 + if codes[0] == 19690720: + print(f"{100*noun+verb}") + exit() diff --git a/2019/day 2/P2/input.txt b/2019/day 2/P2/input.txt new file mode 100644 index 0000000..835f660 --- /dev/null +++ b/2019/day 2/P2/input.txt @@ -0,0 +1 @@ +1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,13,1,19,1,19,10,23,2,10,23,27,1,27,6,31,1,13,31,35,1,13,35,39,1,39,10,43,2,43,13,47,1,47,9,51,2,51,13,55,1,5,55,59,2,59,9,63,1,13,63,67,2,13,67,71,1,71,5,75,2,75,13,79,1,79,6,83,1,83,5,87,2,87,6,91,1,5,91,95,1,95,13,99,2,99,6,103,1,5,103,107,1,107,9,111,2,6,111,115,1,5,115,119,1,119,2,123,1,6,123,0,99,2,14,0,0