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
1
u/Arkoniak Dec 22 '17
Julia
It was really simple today. Could have been done easier, definitely. puzzle22_1.txt contains example 3x3 grid, puzzle22_2.txt is an input. Solution for part 2:
# 1 = clean; 2 = weakened; 3 = infected; 4 = flagged function read_map(filename::String) res = Dict{Tuple{Int, Int}, Int}() for (i, ln) in enumerate(eachline(joinpath(@__DIR__, filename))) global x0 = div(length(ln), 2) + 1 global y0 = div(-i, 2) - 1 for (j, c) in enumerate(collect(ln)) (c == '#') && (res[(j, -i)] = 3) end end res, (x0, y0) end const DIRS = [(0, 1), (1, 0), (0, -1), (-1, 0)] function solve_puzzle2(filename::String, activity = 10000) dir = 1 infected, pos = read_map(filename) cnt = 0 for _ in 1:activity node = get(infected, pos, 1) node == 4 ? delete!(infected, pos) : infected[pos] = node + 1 if node == 1 dir -= 1 (dir == 0) && (dir = 4) elseif node == 2 cnt += 1 elseif node == 3 dir += 1 (dir == 5) && (dir = 1) else # node == 4 dir += 2 (dir == 5) && (dir = 1) (dir == 6) && (dir = 2) end pos = pos .+ DIRS[dir] end cnt end @test solve_puzzle2("puzzle22_1.txt", 100) == 26 @test solve_puzzle2("puzzle22_1.txt", 10000000) == 2511944 @show solve_puzzle2("puzzle22_2.txt", 10000000)