import doctest
from typing import List
VOWELS = set("aeiouAEIOU")
def _make_coderbyte_compliant(result: None or List[int]) -> str:
"""Make Coderbyte compliant, the result of find_vowel_square func call
Helper function.
>>> _make_coderbyte_compliant(result=None)
'Not found'
>>> _make_coderbyte_compliant(result=[1, 2])
'1-2'
"""
if result == None:
return "Not found"
return f"{result[0]}-{result[1]}"
def find_vowel_square(matrix: List[str], n: int) -> strlist:
"""Return the top left grid ref of any N x N sq composed of vowels only
If more than one N x N sq exists, return that which is at the most top-left
position.
:param matrix: the matrix as a list of strings, all equal length
:param n: int. The width and height of the vowel square for which to search
:returns: None or list of top, left index coordinated of the found vowel square
>>> find_vowel_square(matrix=["aqree", "ukaei", "ffooo"], n=2)
[3, 0]
>>> find_vowel_square(matrix=["aqrst", "ukaei", "ffooo"], n=2)
[2, 1]
>>> find_vowel_square(matrix=["aqiii", "ukaei", "ffooo"], n=3)
[2, 0]
>>> find_vowel_square(matrix=["aqtyt", "rtrtt", "aaaaa", "ukaei", "ffooo"], n=3)
[2, 2]
>>> find_vowel_square(matrix=["aqtyt", "aaaaa", "aaaaa", "uuuuu", "oooo"], n=4)
[0, 1]
>>> find_vowel_square(matrix=["gg", "ff"], n=2)
"""
height, width = len(matrix), len(matrix[0])
# True if vowel else False
bool_matrix = [[l in VOWELS for l in line] for line in matrix]
for y in range(height-(n-1)):
for x in range(width-(n-1)):
if all(cell for row in bool_matrix[y:y+n]
for row in bool_matrix[x:x+n]):
return [x, y]
return None
if __name__ == "__main__":
import doctest
doctest.testmod()
assert _make_coderbyte_compliant(
result=find_vowel_square(matrix=["aqree", "ukaei", "ffooo"], n=2)) == "3-0"
assert _make_coderbyte_compliant(
result=find_vowel_square(matrix=["gg", "ff"], n=2)) == "Not found"