-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday3.py
More file actions
36 lines (27 loc) · 963 Bytes
/
day3.py
File metadata and controls
36 lines (27 loc) · 963 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
# Advent of Code Day 3
import numpy as np
diagnostics = [i for i in open('day3_input.txt').read().split()]
def binary_diagnostic(diagnostics):
"""
Calculates the gamma and epsilon rate from a a list of
binary numbers which make up the submarine's diagnostic report
Inputs:
diagnostics: list of binary numbers
Returns the product of the gamma and epsilon rate
"""
bin_len = len(diagnostics[0])
gamma = ""
epsilon = ""
for x in range(bin_len):
pos_list = []
for bin in diagnostics:
pos_list.append(bin[x])
gamma_val = np.bincount(pos_list).argmax()
epsilon_val = np.bincount(pos_list).argmin()
gamma = gamma + str(gamma_val)
epsilon = epsilon + str(epsilon_val)
print(gamma)
print(epsilon)
gamma = int(''.join(gamma), 2)
epsilon = int(''.join(epsilon), 2)
return gamma * epsilon