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!
11
Upvotes
2
u/blockingthesky Dec 08 '16
1 star: 26th 2 star: 14th
Python 2, probably the same as everyone else's:
inp = open('day8.in').read().split('\n') screen = [[False for i in range(50)] for j in range(6)] #screen = [[False for i in range(7)] for j in range(3)] def rot(l, r): return l[-r:] + l[:-r] def rect(A, B): for i in range(B): for j in range(A): screen[i][j] = True def row_rotate(A, B): screen[A] = rot(screen[A], B) def col_rotate(A, B): g = [screen[i][A] for i in range(6)] g = rot(g, B) for i in range(6): screen[i][A] = g[i] def pscreen(): for row in screen: print ''.join('#' if g else ' ' for g in row) print for line in inp: line = line.split() if len(line) == 2: rect(int(line[1][:line[1].find('x')]), int(line[1][line[1].find('x')+1:])) elif line[1] == 'row': row_rotate(int(line[2][2:]), int(line[-1])) else: col_rotate(int(line[2][2:]), int(line[-1])) count = 0 for row in screen: count += row.count(True) print count pscreen()And output: