simeonshopov

Find the eggs

Apr 27th, 2020
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. from itertools import cycle
  2.  
  3. def find_strongest_eggs(*args):
  4.     strongest = []
  5.     eggs: list = args[0]
  6.     sub_lists = [[] for _ in range(args[1])]
  7.     for x in cycle(sub_lists):
  8.         if eggs:
  9.             x.append(eggs.pop(0))
  10.         else:
  11.             break
  12.     for x in sub_lists:
  13.         condition_1 = False
  14.         condition_2 = False
  15.         middle = int(len(x) / 2)
  16.         middle_egg = x[middle]
  17.         left = middle - 1
  18.         right = middle + 1
  19.         if middle_egg > x[right] and middle_egg > x[left]:
  20.             condition_1 = True
  21.             while 0 <= left and right < len(x):
  22.                 if x[right] > x[left]:
  23.                     right += 1
  24.                     left -= 1
  25.                     condition_2 = True
  26.                 else:
  27.                     condition_2 = False
  28.                     break
  29.         if condition_1 and condition_2:
  30.             strongest.append(middle_egg)
  31.     return strongest
  32.  
  33.  
  34.  
  35. test = ([-1, 7, 3, 15, 2, 12], 2)
  36. print(find_strongest_eggs(*test))
  37. test = ([-1, 0, 2, 5, 2, 3], 2)
  38. print(find_strongest_eggs(*test))
  39. test = ([51, 21, 83, 52, 55], 1)
  40. print(find_strongest_eggs(*test))
Advertisement
Add Comment
Please, Sign In to add comment