Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Pattern Recognition by Cjkjvfnby
from copy import deepcopy
def checkio(pattern, image):
image =deepcopy(image) # make image copy
pattern_height = len(pattern)
pattern_width = len(pattern[0])
search_height = len(image) - pattern_height + 1
search_width = len(image[0]) - pattern_width + 1
def is_pattern_start(x, y):
for i, row in enumerate(pattern):
for j, val in enumerate(row):
if val != image[x + i][y + j]:
return False
return True
def mark_pattern(x, y):
for i in range(pattern_height):
for j in range(pattern_width):
image[x + i][y + j] += 2
for i in range(search_height):
for j in range(search_width):
if is_pattern_start(i, j):
mark_pattern(i, j)
return image
June 14, 2014
Comments: