···11+import fileinput
22+from utils import transposed
33+44+55+def find_reflections(pattern):
66+ """Returns all possible reflections for pattern."""
77+ sols = []
88+99+ # First try solving as-is, then transpose for vertical reflections.
1010+ for multiplier in [100, 1]:
1111+ for y in range(len(pattern) - 1):
1212+ bad = False
1313+ for a, b in zip(reversed(pattern[:y+1]), pattern[y+1:]):
1414+ if a != b:
1515+ bad = True
1616+ break
1717+1818+ if not bad:
1919+ sols.append((y + 1) * multiplier)
2020+2121+ pattern = transposed(pattern)
2222+2323+ return sols
2424+2525+2626+def unsmudge(pattern, reflection):
2727+ for y in range(len(pattern)):
2828+ for x in range(len(pattern[0])):
2929+ cell = pattern[y][x]
3030+ pattern[y][x] = '.' if cell == '#' else '#'
3131+3232+ for new_reflection in find_reflections(pattern):
3333+ if new_reflection != reflection:
3434+ return new_reflection
3535+3636+ pattern[y][x] = cell
3737+3838+3939+part_1 = 0
4040+part_2 = 0
4141+4242+for pattern in ''.join(fileinput.input()).split('\n\n'):
4343+ pattern = [list(x) for x in pattern.splitlines()]
4444+4545+ reflection = solve(pattern)[0]
4646+ part_1 += reflection
4747+ part_2 += unsmudge(pattern, reflection)
4848+4949+print("Part 1:", part_1)
5050+print("Part 2:", part_2)
5151+