diff options
-rw-r--r-- | 2019/2.in | 1 | ||||
-rwxr-xr-x | 2019/2.py | 33 |
2 files changed, 34 insertions, 0 deletions
diff --git a/2019/2.in b/2019/2.in new file mode 100644 index 0000000..e5ec5f7 --- /dev/null +++ b/2019/2.in @@ -0,0 +1 @@ +1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,6,1,19,1,19,5,23,2,10,23,27,2,27,13,31,1,10,31,35,1,35,9,39,2,39,13,43,1,43,5,47,1,47,6,51,2,6,51,55,1,5,55,59,2,9,59,63,2,6,63,67,1,13,67,71,1,9,71,75,2,13,75,79,1,79,10,83,2,83,9,87,1,5,87,91,2,91,6,95,2,13,95,99,1,99,5,103,1,103,2,107,1,107,10,0,99,2,0,14,0 diff --git a/2019/2.py b/2019/2.py new file mode 100755 index 0000000..9833888 --- /dev/null +++ b/2019/2.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +import sys + +with open("2.in") as f: + arr = [int(x) for x in f.read().strip().split(",")] + +origarr = arr[:] + +def run(n,v): + arr = origarr[:] + arr[1] = n + arr[2] = v + + i = 0 + while arr[i] != 99: + C,a,b,c = arr[i:i+4] + if C == 1: + arr[c] = arr[a] + arr[b] + elif C == 2: + arr[c] = arr[a] * arr[b] + else: + assert False + i += 4 + + return arr[0] + +print(run(12,2)) + +for n in range(100): + for v in range(100): + if run(n,v) == 19690720: + print(100 * n + v) + sys.exit(0) |