added day03

This commit is contained in:
Peter Hudec
2021-12-03 08:24:32 +01:00
parent 12b1058a27
commit 759dee0449
5 changed files with 2070 additions and 0 deletions

25
03/solve01.py Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python
count1=[0,0,0,0,0,0,0,0,0,0,0,0]
count=0
code_len=12
with open("input01.txt", "r") as f:
for line in f:
count += 1
for pos in range(code_len):
if line[pos] == '1':
count1[pos] += 1
gama=''
epsilon=''
for pos in range(code_len):
if (count1[pos] > count/2):
gama=gama+'1'
epsilon=epsilon+'0'
else:
gama=gama+'0'
epsilon=epsilon+'1'
print(int(gama,2) * int(epsilon,2))