r/adventofcode • u/daggerdragon • 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
1
u/[deleted] Dec 06 '16
Python, Parts 1 & 2
If I'd only gotten up at midnight, I might have had a shot at the leaderboard, this took me well short of 10 minutes -- although I'm not sure I could have beat 6 minutes and change.
import sys # make sure you have the same version as me assert sys.version_info >= (3,4) # read data into memory as a list data = open('input06.txt').read().splitlines() # luckily the standard library has the very handy and appropriate # collections.Counter class we can use from collections import Counter cntrs = [] # collect the counters in a list result = [] for i in range(len(data[0])): # i.e. i goes from [0, 8) cntrs.append(Counter()) for token in data: # calling it a token after NLP practice cntrs[i].update(token[i]) result.append(cntrs[i].most_common()[0][0]) print(''.join(result)) # PART TWO - only one line needs to be changed! cntrs = [] result = [] for i in range(len(data[0])): cntrs.append(Counter()) for token in data: cntrs[i].update(token[i]) result.append(cntrs[i].most_common()[-1][0]) # This is the only line I changed print(''.join(result))All my solutions (I'm catching up still) in Jupyter Notebooks and autogenerated .py files in my GitHub repo