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.

35 lines
1.0 KiB

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]
oxymat = np.array(inputs, dtype=int)
comat = np.array(inputs, dtype=int)
for i in range(oxymat.shape[1]):
oxyones = np.count_nonzero(oxymat, axis=0, keepdims=True)
coones = np.count_nonzero(comat, axis=0, keepdims=True)
print(oxymat)
if oxymat.shape[0] > 1:
if oxyones[0, i] >= (oxymat.shape[0] - oxyones[0, i]):
oxymat = oxymat[oxymat[:, i] == 1]
else:
oxymat = oxymat[oxymat[:, i] == 0]
if comat.shape[0] > 1:
if coones[0, i] >= (comat.shape[0] - coones[0, i]):
comat = comat[comat[:, i] == 0]
else:
comat = comat[comat[:, i] == 1]
print(oxymat[0], oxymat[0].dot(2 ** np.arange(oxymat[0].size)[::-1]))
print(comat[0], comat[0].dot(2 ** np.arange(comat[0].size)[::-1]))
print(
oxymat[0].dot(2 ** np.arange(oxymat[0].size)[::-1])
* comat[0].dot(2 ** np.arange(comat[0].size)[::-1]),
)