Advertisement
Guest User

Untitled

a guest
Aug 19th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1.  
  2. def spy_game(nums):
  3.     # Any sequence
  4.     sequence = [0, 0, 7]
  5.  
  6.     # List of booleans indicating, whether current number in sequence was found
  7.     matches = [False for i in range(len(sequence))]
  8.  
  9.     # Index of current element in sequence to check
  10.     current_idx = 0
  11.  
  12.     # Current element in sequence to check
  13.     next_to_check = sequence[current_idx]
  14.  
  15.     # Iterate over nums
  16.     for i in range(0, len(nums)):
  17.  
  18.         # If current number matches currently checked number in sequence
  19.         if nums[i] == next_to_check:
  20.  
  21.             # Mark it as True
  22.             matches[current_idx] = True
  23.  
  24.             # Go to next one unless it's over :(
  25.             current_idx += 1
  26.  
  27.             if current_idx == len(sequence):
  28.                 break
  29.  
  30.             next_to_check = sequence[current_idx]
  31.  
  32.         # If current number does not match next to check
  33.         elif nums[i] not in sequence:
  34.             pass
  35.  
  36.     return all(item == True for item in matches)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement