Find the minimum boost that lets the reindeer win? Sounds like a job for a binary search to me. Let's write a binary search that finds the minimum in a range that satisfies a predicate:
One thing that burned me was the example data is missing a LOT of edge cases the real data will have. For example, the real data:
has opposing groups where one is immune to the other's attacks
can actually result in deadlocks if the last two remained groups are immune to each other, or if their damage/num units combination isn't enough to kill one opposing unit.
Yes I find that annoying. But I guess it's like the real world too, and the answer is almost always in the detail of the text description, even if it takes several reads to jump out at you.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Part 2
Find the minimum boost that lets the reindeer win? Sounds like a job for a binary search to me. Let's write a binary search that finds the minimum in a range that satisfies a predicate:
We'll need some boosting helpers:
A predicate to test a candidate, for use with the search:
And the answer becomes a matter of finding the minimum boost and running part 1 again with that boost:
And yet again, I have a solution that works for the example and not for the real data. Probably the most frustrating aspect of Advent of Code.
One thing that burned me was the example data is missing a LOT of edge cases the real data will have. For example, the real data:
Yes I find that annoying. But I guess it's like the real world too, and the answer is almost always in the detail of the text description, even if it takes several reads to jump out at you.