elaborated on an alternative syntax in day 2

This commit is contained in:
gabe 2022-08-20 22:54:25 -05:00
parent 64e7a253f2
commit e6354cf097

View file

@ -21,7 +21,9 @@ def parse(puzzle_input: str):
def part1(data): def part1(data):
"""Solve part 1""" """Solve part 1"""
test = lambda x: x.first<=x.password.count(x.letter)<=x.second test = lambda x: x.first<=x.password.count(x.letter)<=x.second
return sum(1 for p in data if test(p)) # these two lines are equivilant.
# return sum(1 for p in data if test(p))
return len([1 for p in data if test(p)])
def test_password(passwordSpec: PasswordSpec): def test_password(passwordSpec: PasswordSpec):
if passwordSpec.password[passwordSpec.first-1]==passwordSpec.letter: if passwordSpec.password[passwordSpec.first-1]==passwordSpec.letter: