Working out solutions for Advent of Code
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.

04a.py 563B

1234567891011121314151617181920212223242526
  1. # Python 3.7
  2. def main():
  3. rangeStart = 109165
  4. rangeEnd = 576723
  5. count = 0
  6. for pw in range(rangeStart, rangeEnd):
  7. count += validatePassword(pw)
  8. print(count)
  9. def validatePassword(pw):
  10. pwStr = str(pw)
  11. # does it have a doubled digit
  12. # does it have a descending digit
  13. c, d = 0, 0
  14. for i in range(1, len(pwStr)):
  15. if pwStr[i-1] == pwStr[i]:
  16. c = 1
  17. if int(pwStr[i]) < int(pwStr[i-1]):
  18. d = 1
  19. if c == 0 or d == 1:
  20. return 0
  21. return 1
  22. if __name__ == "__main__":
  23. main()