Erster Teil, Tag 3

This commit is contained in:
Reiko Kaps 2021-12-03 09:48:58 +01:00
parent ec91d5c824
commit 447338b9b7
2 changed files with 1081 additions and 0 deletions

1000
2021/03/input.txt Normal file

File diff suppressed because it is too large Load Diff

81
2021/03/part-001.py Executable file
View File

@ -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)))