Advertisement
Guest User

Advent of Code Day 4

a guest
Dec 6th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. class testIO:
  2.   def mini(): return 387638
  3.   def maxi(): return 919123
  4.  
  5. def isAscending(password):
  6.   m = 10
  7.  
  8.   while password > 0:
  9.     nextDigit = password % 10
  10.     if nextDigit > m:
  11.       return False
  12.     else:
  13.       password = int(password / 10)
  14.       m = nextDigit
  15.  
  16.   return True
  17.  
  18. def isDoubled(password):
  19.   for i in range(10):
  20.     if str(password).count(str(i)) == 2:
  21.       return True
  22.  
  23.   return False
  24.  
  25. def isValid(password):
  26.   return isAscending(password) & isDoubled(password)
  27.  
  28. def countPasswords(mini, maxi):
  29.   k = 0
  30.   for i in range(mini, maxi):
  31.     if isValid(i):
  32.       k +=1
  33.  
  34.   return k
  35.  
  36. print(countPasswords(testIO.mini(), testIO.maxi()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement