You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

day2a.py 594B

4 lat temu
1234567891011121314151617181920212223
  1. import re
  2. def checkpw(a, b, l, pw):
  3. print(a, b, l, pw)
  4. c = pw.count(l)
  5. if a <= c <= b:
  6. return True
  7. return False
  8. def main():
  9. patt = re.compile("^(\d+)-(\d+) (.): (.+)$")
  10. with open("input2.txt") as file:
  11. lines = file.readlines()
  12. ln = []
  13. for line in lines:
  14. m = re.match(patt, line)
  15. ln.append([int(m.group(1)), int(m.group(2)), m.group(3), m.group(4)])
  16. valid = [pw for pw in ln if checkpw(pw[0], pw[1], pw[2], pw[3])]
  17. print(f"There are {len(valid)} valid passwords out of {len(ln)}.")
  18. if __name__ == "__main__":
  19. main()