Inspired by this and this which was inspired by the first question.
I've set my farmers' fields on fire, but unfortunately they saw me do it! If I don't deal with this situation they could report me and then I'd get arrested! So, that shouldn't be too hard. All I have to do is kill them with fire!
The field will be an m*n
grid with odd m
and n
where both are one greater than a multiple of 4. The farmer starts out in the middle of the field. Each "tick", the farmer can move to an adjacent square (edge or corner) and any space on fire will ignite every grid adjacent to it in a 3x3 space (edge or corner again).
Note: fires and farmers can move diagonally.
The grid will be given as some 2D array of 3 unique values: F
ire, .
Wheat, and H
uman (Farmer). For example:
F...F
F...F
FFHFF
F...F
F...F
the farmer is doomed to DIE! >:-D
It would be easy if I could just light a fire right beside the farmer and set him on fire. However, he knows I am in the field with him and he has a gun. If he sees me, I'm dead. So, I can't light the fire within half of the distance between him and the edge, of him. Essentially, if you floordiv the width of the grid by 4, I must be within that many spaces from the edge, and same with the height.
I am immune to fire so I don't have to worry about getting myself out.
The question is:
Given a field with wheat, a farmer in the center, and potentially existing fires around the field, how many fires do I need to light to guarantee I can kill the farmer?
Test Cases
These test cases have input represented by a F . H
grid and output as a single integer. You may take input in any other reasonable format and output a single integer.
FFFFF
F...F
F.H.F => 0, the farmer is doomed to die in 2 ticks anyway
F...F
FFFFF
FFFFF
F....
F....
F....
F.H.. -> 1 (just light a fire on the far right side of him)
F....
F....
F....
FFFFF
.....
.....
..H.. -> 4 (to ensure his demise, you would need to light 4 points around the perimeter (with rotational symmetry). Any 4 will do.
.....
.....
Rules
- Standard Loopholes apply
- You can take an array of 2 values if you would like, where you infer the farmer's position from the size (since the farmer will always be in the center)