Update day 20 solution
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -2,24 +2,29 @@
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def enhance(algorithm, in_image, b):
|
||||
def enhance(algorithm, in_image, boundary):
|
||||
out_image = []
|
||||
for i in range(-b, len(in_image) + b):
|
||||
height = len(in_image)
|
||||
width = len(in_image[0])
|
||||
for i in range(-boundary, height + boundary):
|
||||
line = ''
|
||||
for j in range(-b, len(in_image[0]) + b):
|
||||
valid = False
|
||||
for j in range(-boundary, width + boundary):
|
||||
idx = ''
|
||||
for k in range(i - 1, i + 2):
|
||||
for l in range(j - 1, j + 2):
|
||||
if 0 <= k < len(in_image) and \
|
||||
0 <= l < len(in_image[k]) and\
|
||||
if 0 <= k < height and \
|
||||
0 <= l < width and \
|
||||
'#' == in_image[k][l]:
|
||||
idx += '1'
|
||||
else:
|
||||
idx += '0'
|
||||
|
||||
idx = int(idx, 2)
|
||||
if not valid and '#' == algorithm[idx]:
|
||||
valid = True
|
||||
line += algorithm[idx]
|
||||
out_image.append(line)
|
||||
if valid:
|
||||
out_image.append(line)
|
||||
return out_image
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user