···11+import fileinput
22+from utils import parts
33+44+55+# Read problem input.
66+RANGES = []
77+for line in fileinput.input():
88+ for r in line.split(','):
99+ x, y = r.split('-')
1010+ RANGES.append((int(x), int(y)))
1111+1212+1313+# Solve puzzle.
1414+PART_1 = 0
1515+PART_2 = 0
1616+1717+for x, y in RANGES:
1818+ part_1_invalids = set()
1919+ part_2_invalids = set()
2020+2121+ for n in range(x, y + 1):
2222+ invalid = False
2323+ for d in range(2, len(str(n)) + 1):
2424+ n = str(n)
2525+ if len(n) % d != 0:
2626+ continue
2727+2828+ # Split the string `n` into `d` parts and
2929+ # check if they're all the same string.
3030+ if len(set(parts(n, d))) == 1:
3131+ if d == 2:
3232+ part_1_invalids.add(int(n))
3333+3434+ part_2_invalids.add(int(n))
3535+ break
3636+3737+ PART_1 += sum(part_1_invalids)
3838+ PART_2 += sum(part_2_invalids)
3939+4040+4141+print("Part 1:", PART_1)
4242+print("Part 2:", PART_2)