func Match(pattern string, input string) bool {
// init memo matrix
M := make([][]bool, len(input)+1)
for i := 0; i <= len(input); i++ {
M[i] = make([]bool, len(pattern)+1)
}
// base case
// empty pattern matches empty string
M[0][0] = true
for i := 1; i <= len(input); i++ {
// cannot match empty pattern against non-empty string
M[i][0] = false
}
for j := 1; j <= len(pattern); j++ {
// asterisks match empty string
// iff they are leading
if pattern[j-1] == '*' {
M[0][j] = M[0][j-1]
} else {
M[0][j] = false // redundant
}
}
//case 1: p[j - 1] == a[i - 1] || p[j - 1] == '?' . Inherit from diagonal
//case 2: p[j - 1] == '*'
//case 2a: Match nothing, M[i][j] = M[i][j - 1]. Matching nothing against prev input char
//case 2b: Match one or more, M[i][j] = M[i - 1][j]. Matching wildcard to cur input char
//case 3: p[j - 1] != a[i - 1] False. Can not match no matter what
for i := 1; i <= len(input); i++ {
for j := 1; j <= len(pattern); j++ {
if pattern[j - 1] == input[i - 1] || pattern[j - 1] == '?' {
M[i][j] = M[i - 1][j - 1]
} else if pattern[j - 1] == '*' {
M[i][j] = M[i][j - 1] || M[i - 1][j]
} else {
M[i][j] = false
}
}
}
return M[len(input)][len(pattern)]
}