Advertisement
ralig

Advent Of Code 2020 Day 2 Part 1

Dec 2nd, 2020 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. from pathlib import Path
  2.  
  3. path = Path(__file__).parent / "../../input.txt"
  4. with path.open() as f:
  5. pws = f.readlines()
  6.  
  7. countValid = 0
  8. #for q in range(0,len(pws)):
  9. for policy in pws:
  10. pwInfo = policy.split()
  11. policyAmts = pwInfo[0].split("-")
  12. policyMin = int(policyAmts[0])
  13. policyMax = int(policyAmts[1])
  14. policyLetter = pwInfo[1][0]
  15. pw = pwInfo[2]
  16.  
  17. pwLetterCount = pw.count(policyLetter)
  18. if pwLetterCount >= policyMin and pwLetterCount <= policyMax:
  19. countValid += 1
  20.  
  21. print(countValid)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement