39
4
Given a rectangular haystack of size at least 2x2 composed of all the same printable ASCII characters, output the location (counting from the top-left) of the needle which is a different character.
For example, if the following haystack is input:
#####
###N#
#####
#####
The output should be 3,1
when zero-indexed (what I'll be using in this challenge) or 4,2
when one-indexed.
The haystack can be composed of any printable ASCII character:
^^^
^^^
^N^
^^^
^^^
^^^
output: 1,2
and the needle will be any other printable ASCII character:
jjjjjj
j@jjjj
jjjjjj
output 1,1
It's also possible to have a needle in the corner:
Z8
88
output 0,0
88
8Z
output 1,1
or to have the needle at the edge:
>>>>>>>>>>
>>>>>>>>>:
>>>>>>>>>>
output 9,1
Rules and Clarifications
- Input and output can be given by any convenient method. This means you can take input as a list of list of characters, as a single string, etc.
- You can print the result to STDOUT or return it as a function result. Please state in your submission what order the output is in (i.e., horizontal then vertical, as used in the challenge, or vice versa).
- Either a full program or a function are acceptable.
- You do not get to pick which characters to use. That's the challenge.
- The haystack is guaranteed to be at least 2x2 in size, so it's unambiguous which is the needle and which is the hay.
- There is only ever one needle in the input, and it's only ever one character in size.
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
Suggested test case:
88\n8Z
(with any two characters of course). – Kevin Cruijssen – 2019-02-01T14:24:03.643Can we take input as a multi-dimensional array? i.e. [ ['#','#','#','#','#'], ['#','#','#','N','#'], ['#','#','#','#','#'], ['#','#','#','#','#'] ]; – 640KB – 2019-02-01T14:39:08.053
2@gwaugh Like a list of list of characters? Yes, that's fine (and explicitly called out as OK). – AdmBorkBork – 2019-02-01T14:40:25.973
3Can we take input as a pair of a string without newlines and the width (or height) of the haystack? i.e.
("########N###########", 5)
– my pronoun is monicareinstate – 2019-02-01T15:17:50.5503
@someone Yes, though it doesn't have a real quorum, I feel that should be allowed.
– AdmBorkBork – 2019-02-01T15:32:05.040On the topic that @someone asked, can we take input as pair of string w/o NL and width as function params? – 640KB – 2019-02-01T19:18:50.153
@gwaugh Yes, that's fine. – AdmBorkBork – 2019-02-01T19:23:02.190
@AdmBorkBork would a numpy array of
int32
be fine as input? (note that numpy does have char arrays as well) – ASCII-only – 2019-02-04T08:32:19.137@ASCII-only If
int32
is the only way to take input, that would be OK, but given thatchar
arrays are possible, I'm going to rule that numpy must use char arrays. – AdmBorkBork – 2019-02-04T13:39:43.960What about
##\n@@
i.e. same amount of both characters – FireCubez – 2019-02-04T20:37:20.853@FireCubez There's only one needle. I can make that explicitly clear, if you think it's necessary? – AdmBorkBork – 2019-02-04T20:47:29.947
i.e. input is guaranteed to only have one needle? I think you should clear that up, since I got confused at first. – FireCubez – 2019-02-04T20:50:54.150
@FireCubez Added. Thanks! – AdmBorkBork – 2019-02-04T20:56:49.903
"The haystack is guaranteed to be at least 2x2 in size" – does this mean it's guaranteed to be at least 2 wide and 2 high, or that it's guaranteed to be at last 4 characters in area? – Deadcode – 2019-02-04T22:48:41.943
@Deadcode I think also 3x1 or 1x3 may be correct. It could be enough to have one needle different from the rest from my point of view. – AZTECCO – 2019-02-06T00:18:13.100
@Deadcode Guaranteed at least 2 wide and 2 high. While AZTECCO is correct that 1x3 or 3x1 is enough to distinguish the needle and hay, such a situation will never happen. – AdmBorkBork – 2019-02-06T13:48:56.463