added day03
This commit is contained in:
25
03/solve01.py
Normal file
25
03/solve01.py
Normal 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))
|
||||
Reference in New Issue
Block a user