Solution to problem 4 part 1 in Python
This commit is contained in:
parent
d3c2917e6e
commit
ee5f84f2e6
33
src/Year_2017/P4.py
Normal file
33
src/Year_2017/P4.py
Normal file
@ -0,0 +1,33 @@
|
||||
# --- Day 4: High-Entropy Passphrases ---
|
||||
|
||||
# A new system policy has been put in place that requires all accounts to use a
|
||||
# passphrase instead of simply a password. A passphrase consists of a series of
|
||||
# words (lowercase letters) separated by spaces.
|
||||
|
||||
# To ensure security, a valid passphrase must contain no duplicate words.
|
||||
|
||||
# For example:
|
||||
|
||||
# aa bb cc dd ee is valid.
|
||||
# aa bb cc dd aa is not valid - the word aa appears more than once.
|
||||
# aa bb cc dd aaa is valid - aa and aaa count as different words.
|
||||
|
||||
# The system's full passphrase list is available as your puzzle input. How many
|
||||
# passphrases are valid?
|
||||
|
||||
with open("files/P4.txt") as f:
|
||||
passphrase_list = [line for line in f.read().strip().split("\n")]
|
||||
|
||||
|
||||
def part_1() -> None:
|
||||
valid = sum(
|
||||
1
|
||||
for passphrase in passphrase_list
|
||||
if len(passphrase.split()) == len(set(passphrase.split()))
|
||||
)
|
||||
|
||||
print(f"There are {valid} valid passphrases")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
part_1()
|
Loading…
Reference in New Issue
Block a user