Created
December 2, 2020 07:58
-
-
Save redspider/7b09be59fa950dd2abcc2dfe9653c821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
valid = 0 | |
# Part 1 | |
for line in INPUT.split("\n"): | |
m = re.match(r"(\d+)-(\d+) (\S): (\S+)", line) | |
(low, high, character, password) = m.groups() | |
if int(low) <= password.count(character) <= int(high): | |
valid += 1 | |
print(valid) | |
# Part 2 | |
valid = 0 | |
for line in INPUT.split("\n"): | |
m = re.match(r"(\d+)-(\d+) (\S): (\S+)", line) | |
(first, second, character, password) = m.groups() | |
def is_character_at(position): | |
return password[int(position) - 1] == character | |
if is_character_at(first) ^ is_character_at(second): | |
valid += 1 | |
print(valid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment