22
4
The Challenge
Given a rectangular grid of characters
A B C D E F G H I J K L M N O P Q R S T
and a grid with the same dimensions of dots and spaces
. . . . . . . . . . .
Output the string which is generated by following the dots through the grid starting in the upper left corner. This example would yield ABGLQRSNIJE
Notes
- You may take the input grids as 2D-arrays or the closest alternative in your language instead of a multiline string.
- You may use the NULL value of your language instead of spaces. But you have to use dots to mark the path.
- You dont need to seperate dots on the same line with spaces. I just added them for readability.
- The smallest possible grid has the size 1x1.
- The start and end dot will have only one neighbour. The dots between them will always have exact two vertical or horizontal neighbours. This guarantees that the path is unambiguously.
- The path will not go diagonal.
- The characters in the grid will be either all upper- or lowercase characters in the range
[a-z]
whatever is most convenient for you. - The path will always start in the upper left corner.
Rules
- Function or full program allowed.
- Default rules for input/output.
- Standard loopholes apply.
- This is code-golf, so lowest byte-count wins. Tiebreaker is earlier submission.
Test cases
Grid #1
A B C A B C W D E F G H U Q X L U S D Q Z A S U K W X I W U K O A I M A I A I O U P
. . . . . . . . . . . . => ABEFGSKUSAWA
. . . . . . . . . . . . . . . . . . . . . . . . . => ABCABCWQZIMPUOIAIAWAXLUUK
Grid #2
Note the triple spaces in the second lines of the first and second examples.
A B C D
. => A
. . => AB
. . . => ACD
Grid #3
A
. => A
Happy Coding!
Are you sure the second test case for Grid #1 is correct? I think the output should be
ABCABCUQXIUOIAIAWAXLUUK
. – vaultah – 2016-03-05T20:45:02.440@vaultah Thaks for the hint, corrected it. Had the dots in the grid one column to far on the left. – Denker – 2016-03-05T20:54:21.160
Do we need to accept input with every other character a space, as here, or can it be just letters and newlines (and no extra spaces in the dot matrix)? – msh210 – 2016-03-06T06:36:55.430
@msh210 As said in the challenge, you may use some kind of NULL value instead of spaces, given of course you take the input as a 2D array. – Denker – 2016-03-06T14:53:24.553
I meant, with nothing at all, not even a null byte. – msh210 – 2016-03-06T15:25:30.620
@msh210 You need some kind of seperator between the dots otherwise you can't follow the path that they are forming. Or do I understand you wrong? What specific input format do you have in mind? – Denker – 2016-03-06T15:30:27.527
The same as yours, but with the even-numbered bytes removed from each line. – msh210 – 2016-03-06T15:41:48.557
@msh210 Ah, now I get it. Sure thats fine. I just added the extra spaces between the dots for readability. – Denker – 2016-03-06T15:47:10.497