Skip to content

Commit dc7f9fc

Browse files
committed
Day 2 (ewwww)
1 parent 601e2dc commit dc7f9fc

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

day2.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#AOC 2019 Brianna Frye
2+
#Day 2
3+
4+
def parse_to_array(base_file):
5+
data_left = True
6+
output_array = []
7+
try:
8+
file = open(base_file)
9+
while data_left == True:
10+
temp = file.readline()
11+
if temp == '':
12+
data_left = False
13+
break
14+
output_array = temp.split(',')
15+
file.close()
16+
return output_array
17+
except IOError:
18+
print('File does not exist!')
19+
finally:
20+
print('Parsing complete!')
21+
22+
data = parse_to_array('day2input.txt')
23+
print(data)
24+
25+
i = 0
26+
while(True):
27+
opcode = int(data[i])
28+
print('opcode: ' + str(opcode))
29+
storage = int(data[i + 3])
30+
print('storage: ' + str(storage))
31+
if opcode == 1:
32+
result = int(data[int(data[i + 1])]) + int(data[int(data[i + 2])])
33+
#print(str(data[i + 1]) + ' + ' + str(data[i + 2]) + ' = ' + str(result))
34+
elif opcode == 2:
35+
result = int(data[int(data[i + 1])]) * int(data[int(data[i + 2])])
36+
#print(str(data[i + 1]) + ' * ' + str(data[i + 2]) + ' = ' + str(result))
37+
elif opcode == 99:
38+
print('stopping!')
39+
break
40+
else:
41+
print('YA DONE GOOFED')
42+
data[storage] = result
43+
i += 4
44+
45+
print(data)

day2input.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1,53,98,3,1,1,2,3,1,3,4,3,1,5,0,3,2,6,1,19,2,19,9,23,1,23,5,27,2,6,27,31,1,31,5,35,1,35,5,39,2,39,6,43,2,43,10,47,1,47,6,51,1,51,6,55,2,55,6,59,1,10,59,63,1,5,63,67,2,10,67,71,1,6,71,75,1,5,75,79,1,10,79,83,2,83,10,87,1,87,9,91,1,91,10,95,2,6,95,99,1,5,99,103,1,103,13,107,1,107,10,111,2,9,111,115,1,115,6,119,2,13,119,123,1,123,6,127,1,5,127,131,2,6,131,135,2,6,135,139,1,139,5,143,1,143,10,147,1,147,2,151,1,151,13,0,99,2,0,14,0

0 commit comments

Comments
 (0)