-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvent_of_code_day2.py
More file actions
41 lines (34 loc) · 969 Bytes
/
advent_of_code_day2.py
File metadata and controls
41 lines (34 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 3 12:22:07 2019
@author: luis
"""
def run_code(a):
for i in range(0,len(a),4):
if int(a[i])==99:
break
if int(a[i])==1:
a[int(a[i+3])]=int(a[int(a[i+1])])+int(a[int(a[i+2])])
elif int(a[i])==2:
a[int(a[i+3])]=int(a[int(a[i+1])])*int(a[int(a[i+2])])
return a[0]
f=open('input.txt','r')
a=f.readlines()
f.close()
a=a[0].replace(" ","").replace('\n',"").split(",")
for i in range (100):
for j in range(100):
a[1]=i
a[2]=j
if run_code(a)==19690720:
print(100*i+j)
def run_code(a):
for i in range(0,len(a),4):
if int(a[i])==99:
break
if int(a[i])==1:
a[int(a[i+3])]=int(a[int(a[i+1])])+int(a[int(a[i+2])])
elif int(a[i])==2:
a[int(a[i+3])]=int(a[int(a[i+1])])*int(a[int(a[i+2])])
return a[0]