21
Given a 2D string as input, either as a string with newlines or a list of lines, output the coordinates (x, y)
of all the hashes (#
) in the list. The input will only contain hashes and spaces. (and newlines, if you choose to take input as a 2D string)
If there are no hashes, you can output anything.
Output should be unambiguous as to which numbers are paired with which.
Example:
##
Should output:
(0,0), (1,0)
That assumes 0-based indexing, starting from the top left. You may start from any corner, use 0 or 1-based indexing, and/or output y
first. (e.g. in the form y,x
).
More test cases (again, all using 0-based top-left (x, y)
indexing):
#
#####
#
(4, 0), (0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (0, 2)
# ###
### #
(0, 0), (2, 0), (3, 0), (4, 0), (0, 1), (1, 1), (2, 1), (4, 1)
Note that these test cases all list by rows, not by following the path.
You may assume the hashes will form a continuous trail, i.e. # #
will never be the input. (probably won't matter, but in case somebody wants to regex this)
You also can output the coordinates in any order you want, i.e. vertical columns, horizontal rows, or just an unsorted list.
Can we assume the input only contains hashes and spaces? – James – 2017-01-04T18:48:11.980
@DJMcMayhem yes, editing that into the question. – Rɪᴋᴇʀ – 2017-01-04T18:49:29.247
Would this or this be valid output formats?
– Zgarb – 2017-01-04T19:00:30.413@Zgarb basically with the extra 1,1 and the hash? Eh, sure. – Rɪᴋᴇʀ – 2017-01-04T19:03:52.337
Would my alternate format be valid?
– ETHproductions – 2017-01-04T19:06:43.700@FlipTack define flat list? i.e. [1, 2, 3, 4] where [1,2] and [3,4] are the coordinates? No. – Rɪᴋᴇʀ – 2017-01-04T19:41:52.200
What about
[[(0, 0)], [(1, 0), (1, 1), (1, 2), (1, 3)], [(2, 3)]]
- a list for each row, containing its coordinates? – FlipTack – 2017-01-04T19:48:09.647@FlipTack that works, yes. – Rɪᴋᴇʀ – 2017-01-04T19:51:06.400
@EasterlyIrk Would this.. "format" qualify as input?
– devRicher – 2017-01-05T19:20:03.327@devRicher that test case won't happen at all, but I may allow that input format. I'll ping you in chat. – Rɪᴋᴇʀ – 2017-01-05T20:10:49.937