Day 6 - Advent of Code 2016

Working solutions for the day 6 puzzles.

Part One

""" day_06_01.py """

# usage: python3 day_06_01.py < input

data = {}

while True:
    try:
        line = input()
    except EOFError:
        break
    for pos, character in enumerate(line):
        distribution = data.get(pos, {})
        distribution[character] = distribution.get(character, 0) + 1
        data[pos] = distribution

message = ''
for distribution in data.values():
    message += max(distribution.items(), key=lambda x: x[1])[0]

print(message)

Part Two

""" day_06_02.py """

# usage: python3 day_06_02.py < input

data = {}

while True:
    try:
        line = input()
    except EOFError:
        break
    for pos, character in enumerate(line):
        distribution = data.get(pos, {})
        distribution[character] = distribution.get(character, 0) + 1
        data[pos] = distribution

message = ''
for distribution in data.values():
    message += min(distribution.items(), key=lambda x: x[1])[0]

print(message)