|
|
|
|
|
|
|
|
|
|
|
# Python 3.7 |
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
|
|
rangeStart = 109165 |
|
|
|
|
|
rangeEnd = 576723 |
|
|
|
|
|
count = 0 |
|
|
|
|
|
for pw in range(rangeStart, rangeEnd): |
|
|
|
|
|
count += validatePassword(pw) |
|
|
|
|
|
print(count) |
|
|
|
|
|
|
|
|
|
|
|
def validatePassword(pw): |
|
|
|
|
|
pwStr = str(pw) |
|
|
|
|
|
# does it have a doubled digit |
|
|
|
|
|
# but not a tripled etc. digit! |
|
|
|
|
|
# does it have a descending digit |
|
|
|
|
|
c, d, m = 0, 0, "" |
|
|
|
|
|
for i in range(1, len(pwStr)): |
|
|
|
|
|
if pwStr[i-1] == pwStr[i]: |
|
|
|
|
|
if c == 0 and m == "": # it has a doubled digit we haven't seen before |
|
|
|
|
|
c = 1 |
|
|
|
|
|
m = pwStr[i] |
|
|
|
|
|
elif c == 1 and m == pwStr[i]: # it has a doubled digit we HAVE seen before |
|
|
|
|
|
c = 0 # so it doesn't count :( |
|
|
|
|
|
else: # this digit isn't the same as the previous, so reset the memo |
|
|
|
|
|
m = "" |
|
|
|
|
|
if int(pwStr[i]) < int(pwStr[i-1]): |
|
|
|
|
|
d = 1 |
|
|
|
|
|
if c == 0 or d == 1: |
|
|
|
|
|
return 0 |
|
|
|
|
|
return 1 |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
|
main() |