day 06
This commit is contained in:
42
06/part01.py
Executable file
42
06/part01.py
Executable file
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import re
|
||||
import argparse
|
||||
|
||||
|
||||
def load_file(filename):
|
||||
with open(filename) as f:
|
||||
for line in f:
|
||||
yield line.strip()
|
||||
return line
|
||||
|
||||
def find_max_char(data):
|
||||
letters = set(data)
|
||||
letter_max = 0
|
||||
letter = None
|
||||
for l in letters:
|
||||
count = data.count(l)
|
||||
if count > letter_max:
|
||||
letter_max = count
|
||||
letter = l
|
||||
|
||||
return letter
|
||||
|
||||
def main(args):
|
||||
MESSAGE = ""
|
||||
lines = []
|
||||
for LINE in load_file(args.input):
|
||||
lines.append(LINE)
|
||||
|
||||
for p in range(len(lines[0])):
|
||||
token = "".join([x[p] for x in lines])
|
||||
MESSAGE = "{}{}".format(MESSAGE, find_max_char(token))
|
||||
|
||||
print(MESSAGE)
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description='AdventOfCode 2016 Day 01')
|
||||
parser.add_argument('--input', '-i', action='store', required=True, help='input file')
|
||||
args = parser.parse_args()
|
||||
|
||||
main(args)
|
||||
Reference in New Issue
Block a user