10
1
Given 3 input items, a list of coordinate pairs, a 2D string, and a single-character string, output whether the character at each coordinate of the 2D string is equal to the single character. You can take the input in any order and the coordinates may be 1-indexed.
You may take the 2D string as a 2D list, a list of lines, or a 2D string.
Example: (0,0), "#_\n__", "#" -> True
The string is
#_
__
The char at the coordinate (0,0)
(from the top left) is #
. This is equal to the third input item, #
, so you output True
(or any truthy value)
Example: [(0,0), (1,1)], "#_\n_#", "#" -> True
The string is
#_
_#
The characters at the coordinates of (0,0)
and (1,1)
are both #
, so the output is true.
The output is only true iff every coordinate matches a hash. Not every hash has to have a matching coordinate though. If there are no occurrences of the single char (#
in some of the test cases) in the 2D string, the output is still just falsy.
You can assume the coordinates will always be within the bounds of the 2D string.
More test cases: (I put the single char second for ease of readability)
[(0,0), (2,1), (3,0)], #
#_##
#_##
True
[(0,0), (1,1), (3,0)], #
#_##
#_##
False (1,1 is not a hash)
[(1,1)], a
#a##
#a##
True
[(4, 0), (3, 0), (2, 0), (1, 0), (0, 0), (0, 1), (0, 2), (0, 3), (1, 3), (2, 3), (2, 2), (3, 2), (4, 2), (4, 3)], ' '
####
#
#
True
Note the last test case uses spaces as the single char string, and hashes around the spaces.
Related. (inverse of this challenge)
Can we assume that input is a 2d array instead of using "\n"? – rahnema1 – 2017-01-14T15:54:29.063
@rahnema1 not a 2D array, but an array/list of lines yes. – Rɪᴋᴇʀ – 2017-01-14T15:54:56.253
@EasterlyIrk I believe this falls into the category Cumbersome I/O formats
– JungHwan Min – 2017-01-14T16:06:44.037In your first example coordinates are in the format
(row, column)
but in the last example coordinates are in the format(column, row)
. – rahnema1 – 2017-01-14T16:07:47.857@JungHwanMin no, because it trivializes the challenge a bit more. – Rɪᴋᴇʀ – 2017-01-14T16:09:01.447
@rahnema1 ah, thanks for catching that. For reference, you may use either coordinate input method. – Rɪᴋᴇʀ – 2017-01-14T16:09:29.613
@EasterlyIrk Some languages treat strings like an array of chars. Wouldn't that make this challenge trivial already? – JungHwan Min – 2017-01-14T16:10:30.270
1Can the coordinates be 1-indexed? – user41805 – 2017-01-14T16:14:01.317
@KritixiLithos yes, they can. – Rɪᴋᴇʀ – 2017-01-14T16:18:55.523
@JungHwanMin yeah, it would. I don't want to trivialize it any more though. – Rɪᴋᴇʀ – 2017-01-14T16:19:13.003
@EasterlyIrk my point is that there is no difference between allowing 2D arrays and not allowing it because there is no distinction in some languages. – JungHwan Min – 2017-01-14T16:20:54.210
@JungHwanMin eh, I guess I'll allow it. – Rɪᴋᴇʀ – 2017-01-14T16:21:44.040
I'm assuming that the "list of coordinate pairs" can be understood as a 2×N matrix, where N is the number of coordinates. Can you confirm? – Luis Mendo – 2017-01-15T03:09:45.367
@Luis yes that's correct – Rɪᴋᴇʀ – 2017-01-15T03:10:23.307
@EasterlyIrk Thanks for clarifying. Also, can we assume the list / matrix will not be empty? – Luis Mendo – 2017-01-15T03:13:17.957
@Luis yeah, sure – Rɪᴋᴇʀ – 2017-01-15T03:13:53.727