day20: limit transformations to the absolute necessary
This commit is contained in:
parent
91f4d095f1
commit
da5fab3c8c
29
day20.py
29
day20.py
@ -192,9 +192,17 @@ def part2(test_mode=False):
|
||||
seamonster_line_3 = re.compile(r".#..#..#..#..#..#...")
|
||||
seamonster_hashcount = 15 # amount of '#' in the sea monster
|
||||
seamonster_count = 0
|
||||
for _ in range(2):
|
||||
for _ in range(2):
|
||||
for _ in range(4):
|
||||
transformations = [
|
||||
flipHorizontally,
|
||||
flipVertically,
|
||||
flipHorizontally,
|
||||
rotateRight,
|
||||
flipHorizontally,
|
||||
flipVertically,
|
||||
flipHorizontally,
|
||||
]
|
||||
transformation_counter = 0
|
||||
while seamonster_count == 0:
|
||||
for x in range(len(borderless_image) - 2):
|
||||
if s_2 := re.split(seamonster_line_2, borderless_image[x+1]):
|
||||
if s_3 := re.split(seamonster_line_3, borderless_image[x+2]):
|
||||
@ -203,18 +211,7 @@ def part2(test_mode=False):
|
||||
seamonster_count += len(s_2) - 1
|
||||
|
||||
if seamonster_count == 0:
|
||||
borderless_image = rotateRight(borderless_image)
|
||||
else:
|
||||
break
|
||||
|
||||
if seamonster_count == 0:
|
||||
borderless_image = flipHorizontally(borderless_image)
|
||||
else:
|
||||
break
|
||||
|
||||
if seamonster_count == 0:
|
||||
borderless_image = flipVertically(borderless_image)
|
||||
else:
|
||||
break
|
||||
borderless_image = transformations[transformation_counter](borderless_image)
|
||||
transformation_counter += 1
|
||||
|
||||
return full_hash_count - seamonster_count * seamonster_hashcount
|
||||
|
||||
Loading…
Reference in New Issue
Block a user