-3
2
Challenge
You will create a function which takes a matrix filled with letters from the alphabet and determine if a 2x2
square composed of vowels exists.
If a 2x2 square of vowels is found, your function should return the top-left position (row-column) of the square.
If no 2x2 square of vowels exists, then return the string
"not found"
.If there are multiple squares of vowels, return the one that is at the most top-left position in the whole matrix.
Rules
- Matrix must be at least
2x2
- Matrix can only contain letters from the alphabet
- Input can be a String, where each line is separated by
\n
,,
,.
,\t
(\n
meansline break
and\t
TAB) or an array of strings. - Vowels are
a e i o u
.
Example
Given ["abcd", "eikr", "oufj"]
a b c d
e i k r
o u f j
Output: 1-0
Given ["gg", "ff"]
g g
f f
Output not found
Test Cases
Given ["asd", "qie", "euo"]
a s d
q i e
e u o
Output: 1-1
Given ["aqrst", "ukaei", "ffooo"]
a q r s t
u k a e i
f f o o o
Output: 1-2
Given ["ghsdfhsd", "sdfgsdff", "sdfgsdfg"]
g h s d f h s d
s d f g s d f f
s d f g s d f g
Output: "not found"
- Consider the examples as test cases as well
Update
- If you are going to use 1-based index, please clarify it in your answer.
This is code-golf, so the shortest answer in bytes win.
2
If there are multiple squares of vowels, return the one that is at the most top-left position in the whole matrix.
What should happen with that test case :[[p,d,e,o],[w,v,a,i],[e,u,n,c],[e,e,w,v]]
? – The random guy – 2018-04-25T13:26:27.470@Therandomguy You will take the one that is at the most top-left, so first check the top and then the left. The result in that test case would be
0-2
– Luis felipe De jesus Munoz – 2018-04-25T13:29:05.4704I'd recommend relaxing the return if nothing is found to either a false value or an impossible value, rather than a string – Jo King – 2018-04-25T13:37:30.480
1@LuisfelipeDejesusMunoz I phrased my question poorly; can we consistently take only uppercase letters or only lowercase letters in the matrix? – Giuseppe – 2018-04-25T13:40:35.773
@Giuseppe. Yes. Sorry, i misunderstood the question. – Luis felipe De jesus Munoz – 2018-04-25T13:41:21.513
16Having to return an index pair or a string makes this unnecessarily cumbersome in strictly typed languages. – Dennis – 2018-04-25T13:59:10.417
1Agreeing with Dennis, returning any falsy value would seem reasonable. – Nit – 2018-04-26T08:37:17.580
1
This challenge is taken from coderbyte, which is not allowed.
– Laikoni – 2018-04-27T22:22:37.3231
@Laikoni It's allowed to take the challenge from somewhere else and rewrite the statements. Although {@}OP you should link to the source.
– user202729 – 2018-04-28T01:54:57.710