Skip to main content
added 8 characters in body
Source Link
Dave
  • 753
  • 8
  • 16
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"
import doctest

from typing import List


VOWELS = set("aeiouAEIOU")


def _make_coderbyte_compliant(result: None or List[int]):
    """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) -> str:
    """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"
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) -> list:
    """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"
added 23 characters in body
Source Link
Dave
  • 753
  • 8
  • 16
import doctest

from typing import List


VOWELS = set("aeiouAEIOU")


def _make_coderbyte_compliant(result: None or List[int]):
    """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) -> str:
    """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(bool_matrix[y+i][x+j]cell for irow in range(n)bool_matrix[y:y+n]
                   for jrow in range(n)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"
import doctest

from typing import List


VOWELS = set("aeiouAEIOU")


def _make_coderbyte_compliant(result: None or List[int]):
    """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) -> str:
    """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(bool_matrix[y+i][x+j] for i in range(n) for j in range(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"
import doctest

from typing import List


VOWELS = set("aeiouAEIOU")


def _make_coderbyte_compliant(result: None or List[int]):
    """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) -> str:
    """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"
deleted 64 characters in body
Source Link
Dave
  • 753
  • 8
  • 16
import doctest

from typing import List


VOWELS = set("aeiouAEIOU")


def _make_coderbyte_compliant(result: None or List[int]):
    """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) -> str:
    """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(bool_matrix[y][x+i] for i in range(n)):
                if all(bool_matrix[y+i][x+j] for i in range(n) for j in range(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"
import doctest

from typing import List


VOWELS = set("aeiouAEIOU")


def _make_coderbyte_compliant(result: None or List[int]):
    """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) -> str:
    """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(bool_matrix[y][x+i] for i in range(n)):
                if all(bool_matrix[y+i][x+j] for i in range(n) for j in range(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"
import doctest

from typing import List


VOWELS = set("aeiouAEIOU")


def _make_coderbyte_compliant(result: None or List[int]):
    """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) -> str:
    """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(bool_matrix[y+i][x+j] for i in range(n) for j in range(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"
added 239 characters in body
Source Link
Dave
  • 753
  • 8
  • 16
Loading
Post Undeleted by Dave
Post Deleted by Dave
added 1 character in body
Source Link
Dave
  • 753
  • 8
  • 16
Loading
Source Link
Dave
  • 753
  • 8
  • 16
Loading