You will be given a matrix. It contains a ride exit (with a direction), some path, as well as some obstacles. Your goal is to build the longest possible queue line in that space, which connects the ride exit to any path.
Inputs
A grid containing:
- A ride exit with direction, as
U,D,L, orR, depending if the exit is facing up, down, left or right. - Some obstacles, as
X - Some path, as
#
Outputs
A number which is equal to the remaining empty squares which were unable to be filled.
Example
[ "###########", "XXXX #", " D #", " #", " #", "XX ##", "XXXXXXXXX#X" ] [ "###########", "XXXX┏┓┗━━┓#", "!D┏━┛┃┏━━┛#", "┏┛┗┓┏┛┗━━┓#", "┗━┓┃┃┏┓!┏┛#", "XX┗┛┗┛┗━┛##", "XXXXXXXXX#X" ] Result: 2 empty squares (marked by !)
Rules
- All test cases will have a valid route between the ride exit and a path. However, this may be of zero length (i.e.: the exit is directly facing a path, in which case there is zero queue).
- Code golf scoring
Test Cases
Format: number of empty squares map 0 [ "R #", ] 0 [ "R#", ] 0 [ " L # ", " ", " ", " ", " ", " X ", " " ] 27 [ " L # ", " XXXXXXXXX ", " X X ", " X X ", " X X ", " XXXXXXXXX ", " " ] 27 [ " L # ", " ######### ", " # # ", " # # ", " # # ", " ######### ", " " ] 25 [ "R #", " XXXXXXXXX", " XXXXXXXX ", " XXXXXXXX ", " XXXXXXXX ", " XXXXXXXX ", " ", ] 34 [ "# X #", " X ", " X ", " X ", " X ", " X ", "U X " ] 2 [ "###########", "XXXX #", " D #", " #", " #", "XX ##", "XXXXXXXXX#X" ] 