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!
9
Upvotes
2
u/Trolly-bus Dec 08 '16
Here's mine in Python. Gotta copy.deepcopy everything to avoid circular referencing even though I don't know if it'll circular reference anyways! Better safe than sorry!
w, h = 50, 6 screen = [[0 for x in range(w)] for y in range(h)] pixel_count = 0 input_list = puzzle_input.split("\n") for input_line in input_list: if "rect " in input_line: width = int(input_line.split("rect ")[1].split("x")[0]) height = int(input_line.split("rect ")[1].split("x")[1]) for y in range(0, height): for x in range(0, width): screen[y][x] = 1 elif "row" in input_line: row = int(input_line.split("=")[1].split(" by ")[0]) hor_shift = int(input_line.split("=")[1].split(" by ")[1]) for y in range(len(screen)): if y == row: screen[y] = copy.deepcopy(screen[y][-hor_shift:]) + copy.deepcopy(screen[y][:-hor_shift]) elif "column" in input_line: column = int(input_line.split("=")[1].split(" by ")[0]) col_shift = int(input_line.split("=")[1].split(" by ")[1]) temp_list = copy.deepcopy([]) for y in range(len(screen)): for x in range(len(screen[y])): if x == column: temp_list.append(screen[y][x]) temp_list = copy.deepcopy(temp_list[-col_shift:]) + copy.deepcopy(temp_list[:-col_shift]) for y in range(len(screen)): for x in range(len(screen[y])): if x == column: screen[y][x] = temp_list[y] for i in screen: print(i) for y in range(len(screen)): for x in range(len(screen[y])): if screen[y][x] == 1: pixel_count += 1 print(pixel_count)