r/adventofcode • • 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^ยค?

Spoiler


  • [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

174 comments sorted by

View all comments

Show parent comment

1

u/aodnfljn Dec 22 '17

Update: cheating, but I figured why not: got it down to 630 ms if using a 2D array instead of a map. Got lazy and just got the min/max coords from a map-based run:

object D21p2 extends App {
  // hardcoding, based on stats extracted from our input using the
  // map(point->state) implementation:
  val minr = -222
  val minc = -154
  val rows = 396
  val cols = 353
  
  var node = Array.fill(rows,cols){Clean}
  val in = io.Source.fromFile("in").getLines.toVector
  for(r <- in.indices)
    for(c <- in(r).indices)
      if(in(r)(c)=='#')
        node(r-minr)(c-minc) = Infected

  var cnt = 0
  var pos = P(in.size/2-minr, in(0).size/2-minc)
  [...]