First of, I'm aware of this, this and this post about two-dimensional pattern matching, these posts however all don't include wildcard matching. Furthermore, I know there are several papers such as this one that have solved the issue I'm facing. However, I'm only just getting familiar with pattern matching in two dimensional arrays and trying to implement the algorithms in the papers is non-trivial for me at the moment.
Thus, the following problem is what I'm facing.
Given a two dimensional array:
[[1 3 4 5 3 3]
[4 1 4 5 5 2]
[5 4 3 4 4 2] # pattern
[4 5 3 4 1 3] # pattern
[3 3 3 4 4 4] # pattern
[3 4 3 4 2 5] # pattern
[4 5 3 4 1 2] # pattern
[5 1 1 2 4 2]
[2 1 3 2 1 5]
[4 4 1 3 3 1]
[1 4 3 4 4 1]
[5 2 4 4 4 1]]
And the following example pattern (where a ? would indicate the wildcard match):
[[? ? 3 4 ? ?]
[? ? 3 4 ? ?]
[3 3 3 4 4 4]
[? ? 3 4 ? ?]
[? ? 3 4 ? ?]]
How would a function be written that takes in the two dimensional array and the pattern, returning True if the pattern is present in the array or False if it is not?
If possible a generalized solution to this problem would be highly appreciated, as there are numerous distinct patterns that I'm trying to match. If required I'm more than willing to provide additional examples.