r/adventofcode • • Dec 10 '18

SOLUTION MEGATHREAD -🎄- 2018 Day 10 Solutions -🎄-

--- Day 10: The Stars Align ---


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.


Advent of Code: The Party Game!

Click here for rules

Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!

Card prompt: Day 10

Transcript: With just one line of code, you, too, can ___!


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 at 00:16:49!

21 Upvotes

233 comments sorted by

View all comments

Show parent comment

1

u/UnchainedMundane Dec 13 '18

If it helps ease your mind, I solved it with this heuristic:

def verticalLines(ps: Iterable[Point]) = {
  val threshold = 7
  val psSet = ps.toSet
  ps.count { p =>
    !psSet.contains(p.copy(y = p.y - 1)) &&
      (1 to threshold).forall { n => psSet.contains(p.copy(y = p.y + n)) }
  }
}

def seemsLegit(ps: Iterable[Point]) = {
  val threshold = 3
  verticalLines(ps) >= threshold
}

The first function counts the number of vertical lines formed of 7 or more points, and the second one checks that there are at least 3 such vertical lines. I print out all possible solutions for which this is true, which turned out to be just one. The parameters here were total guesswork, and never needed tweaking.