Given a two dimensional array, return the co-ordinates of 'x'.
The co-ordinates should be zero indexed.
The solution should pass the example cases provided.
You may use any programming language.
You should assume you will always get an array as input.
Example test cases:
'Return an empty array if input is an empty array' => []
[]
'Return an empty array if no x found' => []
[
['o', 'o'],
['o', 'o']
]
'Return an empty array if more than one x found' => []
[
['x', 'o'],
['o', 'x']
]
'Return an empty array if more than one x found on the same line' => []
[
['x', 'x'],
['o', 'o']
]
'Return [0,0] when x at top left' => [0, 0]
[
['x', 'o'],
['o', 'o']
]
'Return [4,6] for the example below' => [4, 6]
[
['o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'],
['o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'],
['o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'],
['o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'],
['o', 'o', 'o', 'o', 'o', 'o', 'x', 'o'],
['o', 'o', 'o', 'o', 'o', 'o', 'o', 'o']
]
'Return [4,6] for the example below' => [4, 6]
[
['t', 't', 't', 'o', 'o', 'o', '~', 'o'],
['o', 'r', 'o', 'o', 'o', 'o', 't', 'o'],
['o', 'o', 'o', 's', 'o', 'o', 'o', 'o'],
['o', 'o', 'c', 'o', 'o', 'o', 'o', 'o'],
['o', 'o', 'a', 'a', 'a', 'o', 'x', 'o'],
['d', 'o', 'o', 'o', 'o', 'o', 'o', 'o']
]
Language: PHP
Length:
190117120Solution:
...this is basically Andy's but refactored a little, for 117:
…gah! fails on this array (should give [] as 2 x's on the same row, but gave [4,3]), so even though it passes the tests in the rules, it doesn't really follow the rules
working version for 120: