# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
def wpm(word, ptr):
    m = len(word)
    n = len(ptr)
    matrix = [[True if not i and not j else False for j in range(n + 1)] for i in range(m + 1)]
    for j in range(1, n + 1):
        if ptr[j - 1] == '*':
            matrix[0][j] = matrix[0][j - 1]
    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if ptr[j - 1] == '*':
                matrix[i][j] = matrix[i - 1][j] or matrix[i][j - 1]
            elif ptr[j - 1] == word[i - 1] or ptr[j - 1] == '?':
                matrix[i][j] = matrix[i - 1][j - 1]
    for w in matrix:
        print(w)
    return matrix[m][n]

if __name__=='__main__':
    print(wpm('aab', 'c*a*b'))


# +
def wpm(word, ptr):
    m = len(word)
    n = len(ptr)
    dp = [True if not i else False for i in range(n + 1)]
    for j in range(1, n + 1):
        if ptr[j - 1] == '*':
            dp[j] = dp[j - 1]
    for i in range(1, m + 1):
        dp2 = [False]
        for j in range(1, n + 1):
            if ptr[j - 1] == '*':
                dp2.append(dp[j] or dp2[-1])
            elif ptr[j - 1] == word[i - 1] or ptr[j - 1] == '?':
                dp2.append(dp[j - 1])
            else:
                dp2.append(False)
        dp = dp2
    return dp[n]

if __name__=='__main__':
    print(wpm('aab', 'c*a*b'))
# -



StarcoderdataJupyterScriptsDedupFiltered