Advertisement
Musical_Muze

Day 4, Part 2

Dec 4th, 2019
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. #function to return true if adjacent duplicate numbers
  2. def findDupes(num1):
  3.     value = False
  4.     array1 = list(str(num1))
  5.     for x in range(0,5):
  6.         if(array1[x]==array1[x+1]):
  7.             if(x<=3):
  8.                 if(array1[x+1]!=array1[x+2]):
  9.                     if(x>=1):
  10.                         if(array1[x]!=array1[x-1]):
  11.                             value = True
  12.                     else:
  13.                         value = True
  14.             else:
  15.                 if(array1[x]!=array1[x-1]):
  16.                     value = True
  17.     return value
  18.  
  19. #function to return true if non-decreasing adjacent numbers
  20. def findDown(num1):
  21.     value = True
  22.     array1 = list(str(num1))
  23.     for x in range(0,5):
  24.         if(array1[x]>array1[x+1]):
  25.             value = False
  26.             break
  27.     return value
  28.  
  29. count = 0;
  30.  
  31. #loop to run through the range
  32. for i in range(183564,657475):
  33.     if(findDupes(i) and findDown(i)):
  34.         count += 1
  35.  
  36. print("The number of possible correct passwords is: " + str(count))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement