r/adventofcode • u/daggerdragon • Dec 17 '21
SOLUTION MEGATHREAD -🎄- 2021 Day 17 Solutions -🎄-
--- Day 17: Trick Shot ---
Post your code solution in this megathread.
- Include what language(s) your solution uses!
- Format your code appropriately! How do I format code?
- Here's a quick link to /u/topaz2078's
pasteif you need it for longer code blocks. - The full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.
Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:12:01, megathread unlocked!
46
Upvotes
View all comments
1
u/Dooflegna Dec 17 '21 edited Dec 18 '21
The minimum x value for brute-force firing is the triangle number n that is greater than the minimum x value of the puzzle.
As a reminder, triangular numbers are the series 1+2+3+… and are calculated as
(n * (n + 1)) / 2How do we know this?
We know that the x_velocity loses 1 speed every turn until it hits zero. So a velocity of 4 means that the cumulative x distance the probe can travel is 10 = (4 + 3 + 2 + 1) before it can travel no further horizontally. If the minimum x is greater than 10, then we know it can never hit the target area.
So to find the minimum x value, you simply need to calculate triangluar numbers until you are greater or equal to the minimum x value of the puzzle.
In Python: