day 04
secure container
approach
plain brute force over the range of candidate passwords, which is hard-coded at the top of the file. non_decreasing walks the digits of each number and rejects it as soon as one is smaller than the one before.
to_dict counts how often each digit appears. part 1 keeps the non-decreasing numbers whose largest count is above 1. part 2 keeps the ones where some digit appears exactly twice: since the digits never decrease, equal digits are always next to each other, so a count of exactly 2 means a pair that isn't part of a longer run.
the trick
in a non-decreasing number, counting digits is the same as measuring runs.
python
def part2(r=sr):
nd=[i for i in r if non_decreasing(i)]
l=[i for i in nd if 2 in to_dict(i).values()]
return len(l)