Inspired by this.
Background
The evil farmer has decided to burn your wheat field down in order to drive up the prices. To ensure total destruction, he has also soaked your field in gasoline. Even more unfortunately, you happened to be walking on the field when it was lit on fire, and you must get out quickly to survive.
Challenge
Given a field containing wheat, fire and your location, determine if you can make it out of the field in time.
A field consists of wheat (here represented by .
) and fire (F
). Here your location is marked with a O
. For example:
...F...F
F.......
........
.F......
....O...
...F....
........
.F....F.
Every second you move to any adjacent cell (but not diagonally), and every fire spreads to every adjacent cell. If you can't move to a cell that will not be on fire, you die. If you make it out of the field, you survive. Let's see what happens in this example:
...F...F
F.......
........
.F......
....O...
...F....
........
.F....F.
..FFF.FF
FF.F...F
FF......
FFF.....
.F.F.O..
..FFF...
.F.F..F.
FFF..FFF
FFFFFFFF
FFFFF.FF
FFFF...F
FFFF....
FF.FF.O.
.FFFFFF.
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFF.FF
FFFFF.FF
FFFFFFFO
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFF
FFFFFFFFO <-- you made it out and survived, barely
FFFFFFFF
FFFFFFFF
FFFFFFFF
Rules
- Your input is the field as a grid. You may choose any input format, including a string with line separators or a 2D array.
- You may not take as input the locations for fire and/or yourself.
- You may use any 3 distinct values as wheat, fire and your position, including non-strings for array input.
- Fields are always at least 1x1 in size, rectangular and contain no invalid characters.
- Any field will contain exactly one of the value representing your location, and every other position may or may not be fire.
- Your output is one of two distinct values for "you survive" or "you die", as usual in decision-problem.
- Standard code-golf rules apply.
Test cases
Survived
O
....
.O..
....
FFFFF
.....
..O..
.....
FFFF
FFFO
FFFF
.F....
......
......
.F....
..O...
.FF...
.F....
..FF..
...F...F
F.......
........
.F......
....O...
...F....
........
.F....F.
Didn't survive
FFF
FOF
FFF
F.F
.O.
F.F
....F
.....
..O..
.....
F....
.F....F.
........
........
F..O....
........
.....F..
...F...F
F......F
........
.F......
....O...
...F....
........
.F....F.
F..F
.O..
FF..