17
0
Introduction
A family of seals are stranded upon an iceberg in the Arctic Circle. There is a radio transmitter located on the iceberg which the seals can use to call for help. However, only the daddy seal knows how to operate the radio transmitter. And worse, the ice is very slippery this time of year, so the seals will slide uncontrollably until they hit another seal or slide off the edge of the iceberg, making it very difficult for the daddy seal to reach the radio transmitter. Luckily, one of the seals is a computer scientist, so she decides to write a program to figure out how to manoeuvre the daddy seal to the radio transmitter. As there is not much space on the ice to write a program, she decides to make the program use as little bytes as possible.
Input Description
The seal's program will take input in from STDIN, command line arguments, or user input functions (such as raw_input()
). It cannot be preinitialised in a variable (e.g. "This program expects the input in a variable x
").
The first line of the input consists of two comma separated integers in the form
A,B
Following that is B
lines consisting of A
characters each. Each line can only contain characters out of the following:
.
: The cold, cold, ocean. The map will always have this as a border.#
: A part of the iceberg.a
...z
: A seal that is not the daddy seal on the iceberg.D
: The daddy seal on the iceberg.*
: The radio transmitter.
(Note that the daddy seal is always notated with an uppercase D
. A lowercase d
is simply a regular seal.)
Output Description
According to the following rules regarding how the seals can move, output a list of instructions for the seals on how they should move to get the daddy seal to the radio transmitter.
- Rule: All seals can move up (
U
), down (D
), left (L
), and right (R
). They cannot slide diagonally. - Rule: Upon moving, a seal will continue to move in the same direction until it collides with another seal or falls into the sea.
- If a seal collides with another seal, it will stop moving. The seal it collided with will not move.
- If a seal falls into the sea, it will drown and disappear from the map. That is, it does not act as a collider for other seals and it cannot be moved again.
- Rule: Two seals cannot move at the same time, neither can a seal be moved while another one is still moving. The next seal can only be moved once the previous seal has stopped moving.
- Rule: There is no restriction regarding moving a seal multiple times, or the number of seals that drown.
- Rule: A correct solution will have the daddy seal end at the radio transmitter. The daddy seal cannot simply pass the transmitter while sliding.
The output will consist of several lines, each in the form
A,B
Where A
is the seal to move (D
for the daddy seal, a
...z
for others), and B
is the direction to move the seal (either U
, D
, L
, or R
). Note that you do not need to find the shortest route. Any route that gets the daddy seal to the goal is an acceptable output.
Example Inputs and Outputs
Input:
25,5
.........................
.#######################.
.####D#############*k###.
.#######################.
.........................
Output:
D,R
Input:
9,7
.........
.a#####b.
.#####d#.
.##l*###.
.###m#p#.
.#D#.#c#.
.........
Output (one possible output out of many):
m,R
b,L
D,U
D,R
D,D
D,L
Input:
26,5
..........................
.###..................###.
.l*##########v#########D#.
.###..................###.
..........................
Output (one possible output out of many):
v,D
D,L
If you have any other questions, please ask in the comments.
Will all inputs have a valid solution? If not, what is expected output/behavior? – Geobits – 2015-05-12T01:35:43.840
@Geobits All inputs will have a valid solution. Inputs without solutions are considered invalid and your program can do whatever with them. – absinthe – 2015-05-12T01:37:43.260
Is it permissible to end the program by throwing an exception? – DLosc – 2015-05-12T02:46:59.767
@Dlosc It can throw an exception on invalid inputs. For valid inputs, as long as it outputs a solution before throwing the exception it's fine. – absinthe – 2015-05-12T03:05:59.470
2What happens if a non-daddy seal hits the radio transmitter? Will it stop, or move through it? – Reto Koradi – 2015-05-12T04:50:58.143
I remember pokemon has this kind of puzzle, awesome – Ceeee – 2015-05-12T09:11:33.187
For a javascript answer, a function with a multi line string parameter could go? Like
F("9,7\n.........\n.a#####b.\n.#####d#.\n.##l*###.\n.###m#p#.\n.#D#.#c#.\n.........")
– edc65 – 2015-05-12T17:59:37.080@RetoKoradi All seals will move through the radio transmitter. – absinthe – 2015-05-13T02:32:28.003
This means that the baby seals can also stop on the transmitter? Say if you have part of a row
a###*b
, and you make the movea,R
. If the transmitter does not stopa
, butb
does, this now becomes####ab
. The consequence is that if you only have the text representation of the configuration, the transmitter is now invisible, since it's covered bya
. So you pretty much have to find the transmitter position in the initial configuration, and separately remember what it is. – Reto Koradi – 2015-05-13T02:49:59.413@RetoKoradi Correct. – absinthe – 2015-05-13T02:51:22.957
1That invalidates my solution. :( – DLosc – 2015-05-13T05:59:19.920
Test case with baby seal sliding over transmitter:
8,5 ........ .##c###. .a#*#D#. .##b###. ........
– edc65 – 2015-05-13T08:34:03.613Except for the part about falling into the ocean, you've reinvented the board game Ricochet Robots. – Sparr – 2015-05-13T14:17:42.723