Advertisement
ralig

Advent Of Code 2020 Day 2 Part 2

Dec 2nd, 2020 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 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. policyPos1 = int(policyAmts[0])
  13. policyPos2 = int(policyAmts[1])
  14. policyLetter = pwInfo[1][0]
  15. pw = pwInfo[2]
  16.  
  17. pwLetterCount = pw.count(policyLetter)
  18. if ((pw[policyPos1-1] == policyLetter) != (pw[policyPos2-1] == policyLetter)):
  19. countValid += 1
  20.  
  21. print(countValid)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement