Erster Teil, Tag 3
This commit is contained in:
parent
ec91d5c824
commit
447338b9b7
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,81 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
gamma = []
|
||||
epsilon = []
|
||||
lines = 0
|
||||
|
||||
with open('input.txt', 'r') as myfile:
|
||||
for line in myfile:
|
||||
lines = lines + 1
|
||||
linelaenge = len(line.strip())
|
||||
|
||||
# initialize the arrays
|
||||
for number in range(linelaenge):
|
||||
gamma.append(0)
|
||||
epsilon.append(0)
|
||||
|
||||
with open('input.txt', 'r') as myfile:
|
||||
for line in myfile:
|
||||
# get most common bit
|
||||
for number in range(linelaenge):
|
||||
# print('Nr. {} > {}'.format(number, int(line[number])))
|
||||
if int(line[number]) == 1:
|
||||
#print(int(line[number]))
|
||||
# element does not exists
|
||||
gamma[number] = gamma[number] + 1
|
||||
else:
|
||||
#print(int(line[number]))
|
||||
epsilon[number] = epsilon[number] + 1
|
||||
|
||||
|
||||
print('Gamma: {}'.format(gamma))
|
||||
print('Epsilon: {}'.format(epsilon))
|
||||
|
||||
gamma_copy = gamma
|
||||
epsilon_copy = epsilon
|
||||
|
||||
ga_number = ''
|
||||
ep_number = ''
|
||||
|
||||
for element in gamma_copy:
|
||||
if element > lines/2:
|
||||
ga_number = ga_number + '1'
|
||||
else:
|
||||
ga_number = ga_number + '0'
|
||||
|
||||
for element in epsilon_copy:
|
||||
if element > lines/2:
|
||||
ep_number = ep_number + '1'
|
||||
else:
|
||||
ep_number = ep_number + '0'
|
||||
|
||||
|
||||
print('Gamma-Number: {}/{}'.format(ga_number, int(ga_number, 2)))
|
||||
print('Epsilon-Number: {}/{}'.format(ep_number, int(ep_number, 2)))
|
||||
|
||||
print(int(ga_number, 2) * int(ep_number, 2))
|
||||
|
||||
sys.exit()
|
||||
|
||||
|
||||
# for line in myfile:
|
||||
# # get most common bit
|
||||
# for number in range(linelaenge):
|
||||
# if int(line[number]) > 0:
|
||||
# # element does not exists
|
||||
# if gamma[number] exists:
|
||||
# gamma.insert[number] = line[number]
|
||||
|
||||
|
||||
|
||||
print('Number of lines: {}'.format(lines))
|
||||
print('Line length: {}'.format(linelaenge))
|
||||
|
||||
print('Gamma: {}'.format(gamma))
|
||||
# print('forward: {} depth: {}'.format(forward, depth))
|
||||
# print('Submit value: {}'.format(forward * abs(depth)))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue