return sum(pattern == [row[j:j + ncols] for row in area[i:i + nrows]] for i in
    range(len(area) - nrows + 1) for j in range(len(area[i]) - ncols + 1))
How to match ASCII art segments within ASCII art?