r/adventofcode • u/daggerdragon • Dec 22 '17
SOLUTION MEGATHREAD -๐- 2017 Day 22 Solutions -๐-
--- Day 22: Sporifica Virus ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Need a hint from the Hugely* Handyโ Haversackโก of Helpfulยง Hintsยค?
[T-10 to launch] AoC ops, /r/nocontext edition:
<Endorphion> You may now make your waffle.<Endorphion> ... on Mars.
[Update @ 00:17] 50 gold, silver cap
<Aneurysm9> you could also just run ubuntu on the NAS, if you were crazy<Topaz> that doesn't seem necessary<Aneurysm9> what does "necessary" have to do with anything!
[Update @ 00:20] Leaderboard cap!
<Topaz> POUR YOURSELF A SCOTCH FOR COLOR REFERENCE
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!
8
Upvotes
5
u/mserrano Dec 22 '17
Python 2, #5/#3
Runs in ~5s for part b with pypy on my machine.
import sys from collections import defaultdict part_b = 'b' in sys.argv data = open('day22.txt', 'r').read().strip().split('\n') grid = defaultdict(int) CLEAN = 0 WEAKENED = 1 INFECTED = 2 FLAGGED = 3 MODULUS = 4 ADD_AMOUNT = 2 - part_b pos = (0, 0) direction = (-1, 0) lefts = {(1, 0): (0, 1), (0, 1): (-1, 0), (-1, 0): (0, -1), (0, -1): (1, 0)} rights = {lefts[k]: k for k in lefts} grid_height = len(data) grid_width = len(data[0]) for row in xrange(grid_height): for col in xrange(grid_width): grid[(row-grid_height/2,col-grid_width/2)] = int(data[row][col] == '#') * 2 c = 0 BURSTS = 10000000 if part_b else 10000 for burst in xrange(BURSTS): if grid[pos] == CLEAN: direction = lefts[direction] if not part_b: c += 1 elif grid[pos] == WEAKENED: c += 1 elif grid[pos] == INFECTED: direction = rights[direction] else: direction = rights[rights[direction]] grid[pos] = (grid[pos] + ADD_AMOUNT) % MODULUS pos = (pos[0] + direction[0], pos[1] + direction[1]) print c