-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday1.py
More file actions
26 lines (20 loc) · 770 Bytes
/
day1.py
File metadata and controls
26 lines (20 loc) · 770 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
import numpy as np
import pandas as pd
with open('/Users/relyea/data/input_day1.txt') as aoc_fp:
input_data = [theline.strip() for theline in aoc_fp.readlines()]
thedata = np.array([int(theline.split(',')[0]) for theline in input_data])
N = len(thedata)
thesum = np.zeros((N,N))
for aa in range(N):
for bb in range(aa,N):
thesum[aa,bb] = thedata[aa]+thedata[bb]
rightsum = np.where(thesum == 2020)
theprod = thedata[rightsum[0][0]]*thedata[rightsum[1][0]]
#
thesum = np.zeros((N,N,N))
for aa in range(N):
for bb in range(aa,N):
for cc in range(bb,N):
thesum[aa,bb,cc] = thedata[aa]+thedata[bb]+thedata[cc]
rightsum = np.where(thesum == 2020)
theprod = thedata[rightsum[0][0]]*thedata[rightsum[1][0]]*thedata[rightsum[2][0]]