Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. filtered=[]
  2.  
  3. for num in range(168630, 718099):
  4.     counter = 0
  5.     last = None
  6.     pair_detected = False
  7.     smaller_than = False
  8.     for digit in str(num):
  9.         if last is not None:
  10.             if digit < last:
  11.                 smaller_than = True
  12.             elif digit == last:
  13.                 if not pair_detected:
  14.                     counter += 1
  15.                     if counter == 2:
  16.                         pair_detected = True
  17.                 else:
  18.                     counter += 1
  19.                     if counter >= 3:
  20.                         pair_detected = False
  21.             else:
  22.                 last = digit
  23.                 counter = 1
  24.         else:
  25.             last = digit
  26.             counter = 1
  27.     if not smaller_than and pair_detected:
  28.         filtered.append(num)
  29.  
  30. print(len(filtered))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement