AoC 2020 D2: Password Philosophy

Python | Problem statement | Source code | Tags: Brute force

← Previous Back to AoC Index Next →

Part 1

Nothing to say here. Just parse the input and check the counts.

if count[0] <= password.count(char) <= count[1]:
total += 1
python

Part 2

The left position check is password[ind_range[0] - 1] == char and the right position check is password[ind_range[1] - 1] == char. We want exactly one of them to be true, so we can use !=.

if (password[ind_range[0] - 1] == char) != (password[ind_range[1] - 1] == char):
total += 1
python

← Previous Back to AoC Index Next →