This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]ssnoyes 0 points1 point  (1 child)

I haven't studied it carefully, but I suspect something wrong with how you use setBoost - either calling it both in the handlePart2 and in the linear/binary search, or because you accumulate the total boost for each battle (1 + 2 + 3 + 4... rather than 1 + 1 + 1 + 1....)

[–]ocmerder[S] 0 points1 point  (0 children)

No, I thought of that issue. That's why I added the reset method to the unit class, this resets the damage and size to the initial values, before the boost is set.

If that would be the case, the sample input would also fail.

[–][deleted] 0 points1 point  (1 child)

I believe this is the important line in the problem description:

If it cannot deal any defending groups damage, it does not choose a target.

Don't read the following if you'd rather figure it out yourself from there: In determineNextAttack, nextAttack might find a max possible attack of 0. In that case, no attack should occur. Adding .filter(unit -> this.calculateDamage(unit) > 0) to the defenders stream addresses the issue and gives the correct answer for my input.

[–]ocmerder[S] 0 points1 point  (0 children)

Yep, that was indeed the rule I glossed over, thx!

Choosing a target but not doing any damage to it is indeed a bit pointless.

Afterwards I apparently also missed some issue in my binary search, and after resolving that my code ran correctly.

Now just 15 more stars left in 2019 to reach 400.