You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
497 B
24 lines
497 B
import numpy as np
|
|
|
|
filename = "inputs/day3.input"
|
|
file = open(filename, "rb").readlines()
|
|
inputs = file
|
|
inputs = [list(y.decode().replace("\n", "")) for y in inputs]
|
|
|
|
mat = np.array(inputs, dtype=int)
|
|
|
|
ones = np.count_nonzero(mat, axis=0, keepdims=True)
|
|
|
|
gamma = 0
|
|
epsilon = 0
|
|
|
|
for i in ones[0]:
|
|
if i > 500:
|
|
gamma = gamma * 10 + 1
|
|
epsilon = epsilon * 10
|
|
else:
|
|
gamma = gamma * 10
|
|
epsilon = epsilon * 10 + 1
|
|
|
|
print(int(str(gamma), 2) * int(str(epsilon), 2))
|