The challenge
The shortest code by character count to help Robot find kitten in the fewest steps possible.
Golfers, this is a time of crisis - Kitten gone missing and it's Robot's job to find it! Robot needs to reach Kitten in the shortest path possible. However, there are a lot of obstacles in Robot's way, and he needs you to program a solution for him.
Robot used to have a program do it for him, but that program was lost and Robot have no backup :(.
Robot's runtime is not the best, and the least characters Robot has to read from the source code, the least time it will spend processing, and that means Kitten will be found faster!
Robot's memory contains a map of the location he is currently in with the top representing North, bottom representing South, right representing East and left representing West. Robot is always in a rectangular room of an unknown size surrounded by walls, represented by #
in his radar map. Areas Robot can walk in are represented by a space .
Robot's radar also scans for many obstacles in the room and marks them in various ASCII letters. Robot cannot walk across those obstacles. The radar will mark Kitten as the special ASCII character K
, while Robot's location is marked with R
.
Robot's navigation system works this way: He can understand a duo of direction and number of movement units he should travel to - for example, N 3
means 'go north 3 movement units'. Robot's radar map is made such that a movement unit is one ASCII character. Robot can only go in 4 directions and cannot travel diagonally.
Your task, brave Kitten saver, is to read Robot's radar map once, and output the least amount of directions, with the least movement unit travel distance. Robot is guaranteed to have at least one path to Kitten.
To ensure Robot does not waste time executing a malfunctioning program that will not help Robot find Kitten, I encourage you, brave Kitten saver, to use this output of Robot's past program to ensure no time is wasted on finding Kitten!
Test cases
Input:
######################
# d 3 Kj #
# #
# R #
# q #
######################
Output:
E 13
N 2
Input:
######################
# d r 3 Kj #
# p p #
# T X #
# q s t #
# #
# R o d W #
# #
# g t U #
# #
######################
Output:
N 1
E 10
N 4
E 2
Input:
######################
# spdfmsdlwe9mw WEK3#
# we hi #
# rdf fsszr#
# sdfg gjkti #
# fc d g i #
# dfg sdd #
# g zfg #
# df df #
# xcf R#
######################
Output:
N 1
W 9
N 5
E 4
N 1
E 4
N 1
Code count includes input/output (i.e full program).