VP 56: Password Policies (30 extra)

What You Need

Any computer with Python 3. You can also use an online Python environment, such as https://colab.research.google.com

Problem Statement

Each line of input data has a password policy followed by a password.

For example:


1-3 a: abcde
1-3 b: cdefg
2-9 c: ccccccccc
The password policy indicates the lowest and highest number of times a given letter must appear for the password to be valid. For example, "1-3 a" means that the password must contain a at least 1 time and at most 3 times.

In the above example, 2 passwords are valid. The middle password, cdefg, is not; it contains no instances of b, but needs at least 1. The first and third passwords are valid: they contain one a or nine c, both within the limits of their respective policies.

VP 56.1: Valid Passwords (15 pts)

Use this data:
https://samsclass.info/COMSC122/proj/VP56
How many passwords in that data are valid?

That number is the flag.

Part 2: New Policy

Now consider a different interpretation of the policy statements.

Each policy actually describes two positions in the password, where 1 means the first character, 2 means the second character, and so on. (in these policies, there is no concept of "index zero"!) Exactly one of these positions must contain the given letter. Other occurrences of the letter are irrelevant for the purposes of policy enforcement.

Given the same example list from above:

VP 56.2: New Policy (15 pts)

Use the same data:
https://samsclass.info/COMSC122/proj/VP56
How many passwords are valid according to the new interpretation of the policies?

That number is the flag.

Source

Adapted from the Advent of Code.

Posted 11-3-25
Video added 11-4-25