[Community Puzzle] Target Firing

Thanks for letting me know, looks like I will have to give up on this one then!

I ended up solving it, i will try to figure out how i had higher numbers, itā€™s possible i was killing aliens before they damaged me, at an incorrect turn ratio. I was getting 2800 on the second practice task. Instead of the expected 1700, but getting 3200 (correct) on the first one. So it may have been bad math. possibly not including armor or something. I apologize.

@Skwerl23 If you have counter-examples to say the puzzle is incorrect, prove it.
No need to show how you arrived at it. Just show details of your fighting plan in an example.

1 Like

@java_coffee_cup i think it was entirely my fault, and realized a few micro flaws. I now have a working solution, which BTW confuses the heck out of me. Division is the least i would expect to be correct.

If you read the whole thread carefully it pretty much demonstrates how this division is not only a good heuristic but actually the optimal solution to this problem.
Itā€™s funny that among people who solved this problem, thereā€™s a non negligible proportion who had an intuition of the formula, like ā€œI want to favor low T and high D so letā€™s try to minimize T/D and see if it worksā€, and itā€¦ worked.
Somehow they might have felt like they hacked the problem without fully understanding it.

So yeah if you can relate to this, and wonder if your solution was pure luck or not, and if it woud have worked with other validators, actually yes, it is the optimal solution.

@pardouin would you mind sending me a private message as to why? Maybe an article somewhere that explains it or something.

Hello everyone,

Iā€™m having issues with the last test scenario ā€˜Tickle Warsā€™. I currently pass it in the IDE but not when I submit.
I feel stuck since I have no clue why itā€™s not correct. Any tips?
Thanks

1 Like

do you validate all other IDE tests? Itā€™s the ā€œsameā€ test (ships with damage = 1) but with 8 ships.

1 Like

Yes, I do validate all IDE tests. Thanks for the details, Iā€™ll look into it

2 Likes

I am stuck. In the IDE the only task i do not pass is the swarm, but I dont pass the swarm or close call when i submit the task. currently i am using the metric of damage done to me per turn divided by turns to kill at initiation to sort the targets as priority. i dont want to have to recalculate that metric and resort after every shot is fired but that is the only way i can see to improve my code if that even makes it better at all. any tips would be greatly appreciated

That metric is correct and does not change with time, meaning recalculating it every turn would not change anything. Your problem is likely elsewhere.
Make sure your calculations are done with floats/doubles to avoid automatic integer rounding. Other than that, just print your values to the console to check if somethingā€™s wrong. You fail an IDE test, thatā€™s great, you can debug much more easily than if you simply failed a validator.

1 Like

Maybe youā€™re using a floor instead of a ceil when you calculate the number of turns to kill a target.
Or maybe itā€™s the ā€œyou cannot deal less than 1 damageā€ that is not implemented as it should be in your formula.

1 Like

i had a round hiding where a ceil shoulc have been got it finally. thanks for the tips

1 Like

Rust start code has an issue as type variable is a reserved keyword.

nope. I am having a similar situation.

Thank you for this comment. It was enough to get me past the final validator (I put this in the custom IDE).

This is rough, Iā€™m a pretty beginner coder just doing these puzzles as a means to learn. I started this thinking this was ridiculously hard for my level, but have progressed so much and even surprised myself at what i can accomplish with no help, but alasā€¦ iā€™m stuck.

My issue is that I pass everything, except ā€œThe swarmā€ and ā€œClose Callā€. Both of which I get shield values alot less than I should. The Swarm should be 212, I get -1013. Close call should be 0, I get -866 (I know both should be FLEE if less than 0 but just printed the values to troubleshoot). Every other test case I ace. I really donā€™t want to give up. I also donā€™t want to start typing pseudo code or anything in case it spoils it for anyone else too.

Has anyone encountered problems with taking way too much damage on these two specifically but being fine in every other encounter? The only similarities between the two are both having 20 or more ships.

edit: just to add as iā€™ve seen numerous comments in here about division being the right solution. My own priority system consists of calculating how many turns it takes to kill a ship. this number is taken away from the total amount of turns an encounter will take (turns to kill all ships) which is then multiplied by how much damage this ship takes. ((Total turns - Turns to kill ship) * damage the ship does). The higher this number, the higher the priority it is to kill the ship therefore the highest number of the ships gets targeted first (dead ships get their damage set to 0 so this priority number is also set to 0). This seems foolproof to me and am not convinced yet if this is my issue.

1 Like

My guess is the difference (as you yourself acknowledge) has to do with how you prioritize the ships. Iā€™m curious, given your choice of heuristic

(Total turns - Turns to kill ship) * damage the ship does,

what does the order of attack on The Swarm test look like? Does your code tend to attack all the FIGHTERS first, then CRUISERs? Do you attack the ones that do the most damage first, in descending order?

1 Like

I tried to use DFS to solve the problem but it seemed to have a timeout for The Swarm and Close Call cases. Is there a better algorithm?

Yeah, all you need to do is find the good metric to sort the target.

To get the right comparison function, try to imagine two targets and consider two things:

  • the damage dealt each turn by a target
  • the number of turns it will take to destroy the target
    Based on these two, which target would you chose ?
3 Likes