2023-03-13 23:36:25 +01:00
|
|
|
#!/usr/bin/env python3
|
2023-03-13 21:25:55 +01:00
|
|
|
|
|
|
|
def preproc(puzzle_input):
|
|
|
|
space = tuple(map(int, puzzle_input.split('-')))
|
|
|
|
cands = []
|
|
|
|
for i in range(*space):
|
|
|
|
digs = str(i)
|
|
|
|
|
|
|
|
if sorted(digs) != list(digs):
|
|
|
|
continue
|
|
|
|
if max(digs.count(d) for d in set(digs)) < 2:
|
|
|
|
continue
|
|
|
|
cands.append(i)
|
|
|
|
return cands
|
|
|
|
|
|
|
|
def partI(cands):
|
|
|
|
return len(cands)
|
|
|
|
|
|
|
|
def partII(cands):
|
|
|
|
c = 0
|
|
|
|
for i in cands:
|
|
|
|
digs = str(i)
|
|
|
|
if 2 in [digs.count(d) for d in set(digs)]:
|
|
|
|
c += 1
|
|
|
|
return c
|
|
|
|
|