# Advent of Code 2020: Day 2

For this challenge, I opted to use no Python libraries and just do text parsing.

You should stop reading if you haven't solved this puzzle yet!

#### Part 1

For my solution, I ended up creating two functions. One to verify the password and one to count the number of valid passwords. These could have been combined, but my best coding practices took over and I stopped myself from putting too much into one function.

Here's the code:

```def verify_password(line: str) -> bool:
policy, password = [item.strip() for item in line.split(':')]
bounds = policy[:-2]
letter = policy[-1]
low, high = [int(item) for item in bounds.split('-')]

if low <= letter_count <= high:
return True
return False

for line in data:

if __name__ == "__main__":
data = []
for line in f:
data.append(line.strip())

This code will solve the first part of the problem. Here you open the file, extract each line, and strip off the whitespace from both ends. Once you have the list of strings, you pass them on to your function which counts the number of good passwords.

The brains of the operation are in `verify_password()`which uses a list comprehension to break the line down into a password policy and the password itself. Then you do some checking based on what the policy says and return True if it's good and False if it's not.

#### Part 2

In part 2, the password policy has to be interpreted differently. Rather than repeat the problem statement here, you should go check it out and read how the two differ.

To make this work, I updated the two functions to take in a version argument:

```def verify_password(line: str, version: int = 1) -> bool:
policy, password = [item.strip() for item in line.split(':')]
bounds = policy[:-2]
letter = policy[-1]
low, high = [int(item) for item in bounds.split('-')]

if version == 1:
if low <= letter_count <= high:
return True
elif version == 2:
if letters.count(letter) == 1:
return True
return False

def count_good_passwords(data: list, version: int = 1) -> int:
for line in data:

if __name__ == "__main__":
data = []