Inspired by this Puzzling challenge, and easier version of my previous challenge.
Challenge
A 2D rectangular grid is given, where each cell is either an empty space or a wall. You start at the top left cell, and you need to exit through the bottom right cell. You can move to one of four adjacent cells in one step.
You have some bombs, so that using one bomb will let you break exactly one cell-sized wall and go through it. Can you exit the maze using just what you have?
Input and output
The input is the maze and the initial number of bombs. The maze can be taken as a matrix (or any equivalent) containing two distinct values to represent empty spaces and walls. The top left and bottom right cells are guaranteed to be empty. The number of bombs n
is always a non-negative integer.
The output should be truthy if you can exit the maze using n
or fewer bombs, falsy otherwise. You can output truthy/falsy using your language's convention (swapping is allowed), or use two distinct values to represent true or false respectively.
Standard code-golf rules apply. The shortest code in bytes wins.
Test cases
Uses .#
for spaces and walls.
Input maze
..#..#..
Output: false (for 0 or 1 bomb), true (≥2 bombs)
Input maze
.....
####.
.....
.####
.....
Output: true (for any bombs)
Input maze
.
Output: true (for any bombs)
Input maze
.#.#.
##.##
.###.
Output: false (for ≤2 bombs), true (≥3 bombs)
Input maze
.####
#####
##.##
#####
####.
Output: false (for ≤5 bombs), true (≥6 bombs)
w * h
valid as an input format for a matrix of sizew x h
? \$\endgroup\$w
orh
along with the list). \$\endgroup\$