Advertisement
Guest User

Untitled

a guest
Oct 24th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | Gaming | 0 0
  1.  def find_partners(aliensX, aliensY):
  2.   if len(aliensX) <= 1:
  3.     return aliensX, aliensY
  4.   pivotX = aliensX[0]
  5.   bY, pivotY, aY = partition(pivotX, aliensY)
  6.   bX, _, aX = partition(pivotY, aliensX)
  7.  
  8.   bX, bY = find_partners(bX, bY)
  9.   aX, aY = find_partners(aX, aY)
  10.   return [*bX, pivotX, *aX], [*bY, pivotY, *aY]
  11.  
  12. def partition(pivot, aliens):
  13.   b = []
  14.   p = None
  15.   a = []
  16.   for alien in aliens:
  17.     color = compare_aliens(pivot, alien)
  18.     if color == "white":
  19.       a.append(alien)
  20.     elif color == "black":
  21.       b.append(alien)
  22.     else:
  23.       p = alien
  24.   return b, p, a
  25.  
  26. def compare_aliens(alien_x, alien_y):
  27.     if alien_x == alien_y:
  28.         return "green"
  29.     elif alien_x < alien_y:
  30.         return "white"
  31.     else:
  32.         return "black"
  33.  
  34. # Example usage
  35. alienX = [1, 5, 2, 4, 3, 8, 6, 7]
  36. alienY = [3, 7, 1, 8, 4, 5, 6, 2]
  37.  
  38. partners = find_partners(alienX, alienY)
  39. print("Partners:", partners)
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement