23
4
You're a mouse. Your mouse friends have all been captured, and are unconscious and trapped in a maze that has only one entrance/exit. You happen to have a perfect map of the maze, so you can plot a solution to rush in and carry them all to safety. However, the maze is guarded with a security system that will trigger an alert if a threshold of 1000
is reached, causing you to be captured and fail your rescue mission.
From your previous investigations of the maze, each square you step (i.e., each horizontal or vertical movement -- mice can't move diagonally) adds 1
to the security system's counter. However, if you're carrying a weight (either a block of dynamite or an unconscious mouse friend), it instead adds 2
since it detects the additional pressure. The entrance/exit square doesn't have this security system, and so doesn't add to the counter.
You have an unlimited supply of dynamite that you've brought to the entrance, so you can simply blow up all the walls to free your friends. But you need to be cautious with doing so, since each explosion adds 50
to the counter from the concussive pressure. Additionally, you can only carry one thing at a time, either one mouse or one block of dynamite. Since each block of dynamite can only detonate one wall space, this means that if there are multiple walls in a row, you need to make an empty-handed trip back to the entrance to grab more.
Worked-through example
Suppose our maze looks like the following:
######
#M# E#
######
I'll use c
for the counter. We start at the E
ntrance, move one square left while carrying dynamite, c=2
. We detonate the dynamite to explode the wall, c=52
. We move two squares left, empty-handed, to get c=54
, and we're now standing on the mouse's square. We pick our friend up, and move 3 squares back to the E
xit, but the last square doesn't count since it doesn't have any sensors, so that's only 2 squares with something on our back. That means that when we reach the exit with the final mouse, c=58
, which is less than 1000
, and therefore the mission succeeds.
Challenge
Given an input maze, output whether you, the mouse hero, can successfully rescue all trapped mice within the constraints outlined above, or whether the mission is a failure.
Input
- A 2D maze in any acceptable format (multiline string, array of strings, etc.).
- For this challenge, I will be using
#
for both the interior and exterior walls,M
for the mouse friends, andE
for the entrance. - The entrance will never be immediately adjacent to an interior wall (there will always be at least one space in which to move freely).
- You can substitute any printable ASCII characters you wish so long as it's consistent. This does allow you to use two different symbols for interior walls vs. exterior walls, so long as you maintain consistency (e.g., if you choose to use
@
for interior walls instead, and leave#
for exterior, every interior wall must be@
and every exterior wall#
). - The maze will always be completely bounded by walls, but is not necessarily rectangular. If desired, you can assume that the maze is padded with spaces to make rectangular input (optional).
- The maze may have sections that are unreachable without dynamite.
- You cannot dynamite the exterior walls of the maze.
Output
A truthy/falsey value. Truthy for "Yes, the mouse can rescue every other mouse" or Falsey for "No, the alarm system will be tripped."
The Rules
- Either a full program or a function are acceptable.
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
Examples
Truthy examples, separated by blank lines.
#####
#M E#
#####
######
#M# E#
######
########
#E # M#
# # #
# # #
# #
########
#############################
# ## # # #
# M ## M # # #
# ## # M # E #
#M ## # # #
#############################
###############
#MMMMMMMMMMMMM#
#MMMMMMMMMMMMM#
#MMMMMMMMMMMMM#
#MMMMMMMMMM MM#
#MMMMMMMMMMMME#
###############
Falsey examples, separated by blank lines
#############################
#M ## ## ## #
# M ## M ## ## #
# ## ## M ## E #
#M ## ## ## #
#############################
#############################
########
########
# # #
# M # M#
########
#####
# M #
#####
#####
#####
#####
###################
# # # ## ## # # #
#M#M#M## E ##M#M#M#
# # # ## ## # # #
###################
#######
######
#####
####
# M#
####
###############
#MMMMMMMMMMMMM#
#MMMMMMMMMMMMM#
#MMMMMMMMMMMMM#
#MMMMMMMMMMMMM#
#MMMMMMMMMMMME#
###############
3The mice were furious (mild spoiler) – Luis Mendo – 2016-09-22T14:51:08.367
You're a mouse. Oh, huh. TIL. – Alex A. – 2016-09-22T19:42:29.673
3@AlexA. Sorry that you had to learn it from a stranger on the Internet. ;-) – AdmBorkBork – 2016-09-22T19:51:10.520
2I suspect most people would have a hard time solving this with regular code, let alone golfing it. It's a great challenge that I unfortunately don't currently have time to work on. – Moshe Katz – 2016-09-23T00:13:11.747
2Is it acceptable to have a different char for the external walls (as they're not destrcutible) ? – Tensibai – 2016-09-23T09:54:48.847
1May we assume the maze is space padded so all lines have the same length ? – Ton Hospel – 2016-09-23T11:03:54.247
@Tensibai Yes, that's fine, so long as every external wall is the same character and every internal wall is the same character. I'll explicitly add that into the challenge. – AdmBorkBork – 2016-09-23T12:27:56.250
@TonHospel Yes. I had thought I had that in the challenge, but apparently it's not listed. – AdmBorkBork – 2016-09-23T12:28:21.397
Can an explosion only blow up one wall? It isn't ever explicitly said. – DanTheMan – 2016-09-24T19:36:17.663
Will the entrance ever be adjacent to an internal wall? – DanTheMan – 2016-09-24T19:40:36.017
@DanTheMan Yes, only one wall per explosion. I'll explicitly add that. That's a fair assumption that there's no internal wall immediately next to the entrance, given how the examples are laid out. I'll explicitly add that. – AdmBorkBork – 2016-09-26T12:34:20.770
Can you walk over a mouse and not pick him up ? In particular can you do that while carrying dynamite ? – Ton Hospel – 2016-09-28T07:23:59.253
@TonHospel Sure, I don't see why not. – AdmBorkBork – 2016-09-28T12:25:16.893
2@Moshe Katz, sure you don't have time. You just don't wanna save the Mäuse. – msh210 – 2016-09-28T18:53:31.620
@msh210 :-P Just for that, I think I'll have to find some time. – Moshe Katz – 2016-09-28T18:57:57.563