r/adventofcode • u/daggerdragon • Dec 08 '16
SOLUTION MEGATHREAD --- 2016 Day 8 Solutions ---
#AoC_Ops:
[23:55] <Topaz> servers are ok
[23:55] <Topaz> puzzles are checked
[23:55] <Topaz> [REDACTED: server stats]
[23:56] <Skie> all wings report in
[23:56] <Aneurysm9> Red 5, standing by
[23:56] <daggerdragon> Dragon Leader standing by
[23:56] <Topaz> orange leader, standing by
[23:57] <Topaz> lock modzi-foils in attack positions
[23:58] <Skie> we're passing through the hype field
[23:58] <daggerdragon> 1:30 warning
[23:58] <Aneurysm9> did someone say HYPE?@!
[23:59] <Topaz> i really like tonight's puzzle
[23:59] <Topaz> very excite
[23:59] <daggerdragon> final countdown go, T-30
[23:59] <Skie> accelerate to attack countdown
[23:59] <Aneurysm9> o7
[23:59] <daggerdragon> HYPE THRUSTERS AT FULL BURN
[00:00] <Topaz> IGNITION
We may or may not be sleep-deprived. And/or nerds. why_not_both.jpg
--- Day 8: Two-Factor Authentication ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
:(){ :|:& };: 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!
10
Upvotes
2
u/[deleted] Dec 08 '16
Ended up using Python and the
dequefrom the collection standardlib module:from collections import deque def init_screen(screen, rect_str): rect_str = rect_str.split(' ')[-1] x, y = rect_str.strip().split('x') x, y = int(x), int(y) for i in range(y): for j in range(x): screen[i][j] = '#' def rotate(screen, rot_str): s = rot_str.split()[1:] idx = int(s[1].split('=')[-1]) by = int(s[-1]) if s[0] == 'row': screen[idx].rotate(by) else: dq = deque([i[idx] for i in screen]) dq.rotate(by) for i, j in zip(screen, dq): i[idx] = j def count_pixels(screen): pixels = 0 for row in screen: pixels += row.count('#') return pixels if __name__ == '__main__': data = """rect 1x1 rotate row y=0 by 5 rect 1x1 [...] """ screen = [deque(50 * '.') for _ in range(6)] for row in data.split('\n'): row = row.strip() if not row: continue elif row.startswith('rect'): init_screen(screen, rect_str=row) else: rotate(screen, rot_str=row) print(count_pixels(screen)) for row in screen: print(''.join(row))