I am a big fan of the game Creeper World, and especially the sequel. You don't need to know how this game works to answer the question, I just wanted to mention where my question originated from.
In the game, your objective is to destroy the Emitters that are spawning Creeper, using a weapon known as a nullifier.
Nullifiers can destroy any emitter in this radius:
eee
eeeee
eenee
eeeee
eee
Each nullifier CAN target multiple Emitters.
Your objective
Given an array simulating a 2D map consisting of nothing and emitters with whatever characters you like, could be spaces and e or numbers - just be sure they are distinguishable, output the same map with the optimal amount of nullifiers n (or what you would like) placed, so that the emitters are destroyed with the least amount of nullifiers.
If there are multiple optimal ways of doing it, just outputting one would be fine. If, however, the task is not solvable, say there are so many emitters that no layout will ever hit all of them, you must output a distinguishably different something, null will suffice
Quick Rules:
- Input: multidimensional array
- Input will contain two characters, meaning nothing and emitter, include what is what in your answer
- Output: multidimensional array
- Output will contain three characters, meaning nothing, emitter and nullifier OR a distinguishable output if the input is unsolvable
- You may only replace the nothing character with a nullifier
- A nullifier can hit multiple emitters, and will always hit all that are in range
- A nullifier can hit in the area specified above, and will always hit all emitters that it can target
- Shortest answers in bytes win
- standard loopholes forbidden
Examples
Input:
[[ , ,e, , ],
[ , , , , ],
[e, , , ,e],
[ , , , , ],
[ , ,e, , ]]
Output:
[[ , ,e, , ],
[ , , , , ],
[e, ,n, ,e],
[ , , , , ],
[ , ,e, , ]]
Input:
[[e,e,e,e,e],
[e, , , ,e],
[e, , , ,e],
[e, , , ,e],
[e,e,e,e,e]]
Output:
[[e,e,e,e,e],
[e, ,n, ,e],
[e, , , ,e],
[e, ,n, ,e],
[e,e,e,e,e]]
Input:
[[e, , , , , , ,e, ,e, , , ,e, ,e, ,e, ,e],
[ , ,e, , ,e, , , ,e,e, , , , ,e, , , , ],
[ , ,e, , , ,e, ,e, ,e, ,e, ,e, ,e, , , ],
[e, , , ,e, ,e, , , , , , , , , , , ,e, ],
[e, , ,e, , , , , ,e, ,e, ,e, ,e, , , ,e],
[ , , ,e, ,e, ,e, , , , , , , , , ,e, , ],
[ ,e,e, ,e, , , ,e, ,e,e, ,e, ,e, ,e, , ],
[ , ,e, , , ,e, , , , , , , , ,e,e, ,e, ],
[ , , ,e, , , , ,e,e, , , , , , , , ,e, ],
[e, , , , , , ,e, , , ,e,e, ,e, , , , , ],
[ ,e,e, , ,e, , , , ,e, , , , , , ,e, , ],
[ , , ,e,e, ,e, ,e, , , ,e,e, ,e, ,e, ,e],
[e,e, , , , ,e, , , ,e, , , , , , , , , ],
[ , , ,e, , , , , ,e, , ,e, ,e, ,e, ,e, ],
[ , , , ,e, ,e, , , , , , , , , , , , , ],
[e,e, , ,e,e, , ,e, , ,e, ,e, ,e, ,e, ,e],
[e, ,e, ,e, , ,e,e,e, , ,e, , , ,e, , ,e],
[ , , , ,e, , , , , ,e, , , ,e, , , , , ],
[ , ,e, , , ,e, ,e, , , ,e, , , , ,e, , ],
[ , , ,e, ,e, ,e, , ,e,e, , ,e,e, , ,e, ]]
Output (This output is hand-made, and might not be the optimal output):
[[e, , , , , , ,e, ,e, , , ,e, ,e, ,e, ,e],
[ , ,e, , ,e, , ,n,e,e, , , ,n,e, , , , ],
[ ,n,e, , ,n,e, ,e, ,e, ,e, ,e, ,e, ,n, ],
[e, , , ,e, ,e, , , , , , , , , , , ,e, ],
[e, , ,e, , , , , ,e, ,e, ,e, ,e, , , ,e],
[ , ,n,e, ,e, ,e, , , ,n, , , , , ,e, , ],
[ ,e,e, ,e, ,n, ,e, ,e,e, ,e, ,e,n,e, , ],
[ , ,e, , , ,e, , , , , , , , ,e,e, ,e, ],
[ , , ,e, , , , ,e,e, , , , , , , , ,e, ],
[e, ,n, , , , ,e, , , ,e,e, ,e, , , , , ],
[ ,e,e, , ,e,n, , ,n,e, , , ,n, , ,e,e, ],
[ , , ,e,e, ,e, ,e, , , ,e,e, ,e, ,e, ,e],
[e,e, , , , ,e, , , ,e, , , , , , , , , ],
[ , , ,e, ,n, , , ,e, , ,e, ,e, ,e, ,e, ],
[ ,n, , ,e, ,e, , , , , , , ,n, , , ,n, ],
[e,e, , ,e,e, , ,e,n, ,e, ,e, ,e, ,e, ,e],
[e, ,e, ,e, , ,e,e,e, , ,e, , , ,e, , ,e],
[ , , , ,e, , , , , ,e, ,n, ,e, , ,n, , ],
[ , ,e, ,n, ,e, ,e, , , ,e, ,n, , ,e, , ],
[ , , ,e, ,e, ,e, ,n,e,e, , ,e,e, , ,e, ]]
Input:
[[e,e],
[e,e]]
Output:
null
0
,1
and2
or similar? \$\endgroup\$