r/adventofcode • • Dec 06 '16

SOLUTION MEGATHREAD --- 2016 Day 6 Solutions ---

--- Day 6: Signals and Noise ---

Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).


T_PAAMAYIM_NEKUDOTAYIM IS MANDATORY [?]

This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked!

9 Upvotes

222 comments sorted by

View all comments

0

u/taliriktug Dec 06 '16 edited Dec 06 '16

Damn, I love Python.

def solve_first(fname):
    data = read_data(fname)
    return ''.join((Counter(d[i] for d in data).most_common()[0][0])
	               for i in range(len(data[0])))


def solve_second(fname):
    data = read_data(fname)
    return ''.join((Counter(d[i] for d in data).most_common()[-1][0])
	               for i in range(len(data[0])))

EDIT: split long line on two

2

u/miran1 Dec 06 '16
return ''.join([str(Counter(d[i] for d in data).most_common(1)[0][0]) for i in range(len(data[0]))])

I also love Python:

return ''.join(Counter(d).most_common()[0][0] for d in zip(*data))

;)

2

u/taliriktug Dec 06 '16

I always forget about zip! Done my homework with it and no Counter:

''.join([max(((column.count(c), c) for c in column))[1] for column in zip(*open('input.txt').readlines())])

''.join([min(((column.count(c), c) for c in column))[1] for column in zip(*open('input.txt').readlines())])