diff --git a/day20.py b/day20.py index 10820b2..0492d74 100644 --- a/day20.py +++ b/day20.py @@ -192,29 +192,26 @@ 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): - 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]): - # yes, this is somewhat optimistic, but it results in the correct answer - if len(s_2) > 1 and len(s_2) == len(s_3): - 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 + 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]): + # yes, this is somewhat optimistic, but it results in the correct answer + if len(s_2) > 1 and len(s_2) == len(s_3): + seamonster_count += len(s_2) - 1 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