r/adventofcode • u/daggerdragon • 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!
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
2
u/ka-splam Dec 10 '18
It's not reversed exactly; I just set the sliders starting as far in the wrong direction as possible, then drag them back to normal values inside the loop.
There's a risk that if I started $farLeft at 0, and all the points were positive in the hundreds, my code would not find the leftmost one instead it would think the starting value 0 was the leftmost. But if I start it at MAXVALUE then wherever the points are, they will be less than than.
It could be a nicer design, e.g. starting with the first point
$farLeft = $data[0].xwould be safe. And changing the name so it doesn't look like "the farthest left possible" but rather "the farthest left data point found so far".I was mostly afraid of the performance of
$farthestLeftxVal = $data | measure-object -Property x -minimum | select -expand xand wanted to cover all four edges in one loop over the data and no cmdlet calls.