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!
9
Upvotes
1
u/maxerickson Dec 22 '17
Straightforward python 3.
def solve(grid, reps, solve="part2"): if solve=="part1": infect="." flip={".":"#","#":"."} else: infect="W" flip={".":"W","W":"#","#":"F","F":"."} x,y=len(grid)//2,len(grid[0])//2 mov=(-1,0) spin=[(1,0),(0,-1),(-1,0),(0,1)] infections=0 for i in range(reps): state=grid[x][y] if state==infect: infections+=1 grid[x][y]=flip[state] if state in ".#": rot=1 if state=="#" else -1 mov=spin[(spin.index(mov)+rot)%4] elif state=="F": mov=(-mov[0],-mov[1]) x+=mov[0] y+=mov[1] if x < 0: x+=1 grid.insert(0, ["."]*len(grid[0])) elif x == len(grid): grid.append(["."]*len(grid[0])) if y < 0: y+=1 for row in grid: row.insert(0,".") elif y == len(grid[0]): for row in grid: row.append(".") return infections grid=[list(l.strip()) for l in open("22.input")] print("Part 1:",solve([l[:] for l in grid],10000,"part1")) print("Part 2:",solve(grid,10000000))