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.
38 lines
969 B
38 lines
969 B
import os
|
|
import numpy as np
|
|
|
|
dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
with open(os.path.join(dir, './input.txt'), 'r') as input_file:
|
|
|
|
lines = input_file.readlines()
|
|
|
|
counts = []
|
|
gamma_string = ""
|
|
epsilon_string = ""
|
|
for line in lines:
|
|
clean_line = line.strip()
|
|
for i in range(len(clean_line)):
|
|
char = line[i]
|
|
if len(counts) <= i:
|
|
counts.append(0)
|
|
if char == '1':
|
|
counts[i] = counts[i]+1
|
|
print(counts)
|
|
for item in counts:
|
|
if item > (len(lines)*0.5):
|
|
gamma_string = gamma_string + "1"
|
|
epsilon_string = epsilon_string + "0"
|
|
else:
|
|
gamma_string = gamma_string + "0"
|
|
epsilon_string = epsilon_string + "1"
|
|
|
|
print(gamma_string)
|
|
gamma = int(gamma_string, 2)
|
|
print(gamma)
|
|
|
|
print(epsilon_string)
|
|
epsilon = int(epsilon_string, 2)
|
|
print(epsilon)
|
|
|
|
print(gamma*epsilon)
|