adventofcode.com/2020/02/02.py

31 lines
517 B
Python
Executable File

#!/usr/bin/env python3
# Advent Of Code 2020 - Day 2
"""
1-5 k: kkkkhkkkkkkkkkk
5-7 k: blkqhtxfgktdkxzkksk
"""
filename = "input.txt"
with open(filename) as f:
content = f.readlines()
validPasswords = 0
for i in content:
line = i.split()
xMin = int(line[0].split("-")[0])
xMax = int(line[0].split("-")[1])
character = line[1].rstrip(":")
password = line[2]
if ( xMin <= password.count(character) <= xMax ):
validPasswords = validPasswords + 1
print (validPasswords)