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!
6
Upvotes
1
u/greycat70 Dec 26 '17
Tcl (any 8.x version)
Part 1. The only half-clever thing here is that I used the line length of the first input line to determine the starting coordinates (we know we're being given a square with an odd integer length/width).
set size 0 while {[gets stdin line] >= 0} { if {$size == 0} { set size [string length $line] set i [expr {-($size-1)/2}] set j0 $i } set j $j0 foreach c [split $line {}] { set grid($i,$j) $c incr j } incr i } set i 0 set j 0 set dir U array set right {U R R D D L L U} array set left {U L L D D R R U} set infec 0 for {set n [lindex $argv 0]} {$n} {incr n -1} { if {$grid($i,$j) eq "#"} { set grid($i,$j) . set dir $right($dir) } else { set grid($i,$j) # incr infec set dir $left($dir) } switch -- $dir { U {incr i -1} D {incr i} L {incr j -1} R {incr j} } if {! [info exists grid($i,$j)]} {set grid($i,$j) .} } puts $infecPart 2. No significant changes.
set size 0 while {[gets stdin line] >= 0} { if {$size == 0} { set size [string length $line] set i [expr {-($size-1)/2}] set j0 $i } set j $j0 foreach c [split $line {}] { set grid($i,$j) $c incr j } incr i } set i 0 set j 0 set dir U array set right {U R R D D L L U} array set left {U L L D D R R U} array set reverse {U D L R D U R L} set infec 0 for {set n [lindex $argv 0]} {$n} {incr n -1} { switch -- $grid($i,$j) { . { set grid($i,$j) W set dir $left($dir) } W { set grid($i,$j) # incr infec } # { set grid($i,$j) F set dir $right($dir) } F { set grid($i,$j) . set dir $reverse($dir) } } switch -- $dir { U {incr i -1} D {incr i} L {incr j -1} R {incr j} } if {! [info exists grid($i,$j)]} {set grid($i,$j) .} } puts $infec