Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def find_partners(aliensX, aliensY):
- if len(aliensX) <= 1:
- return aliensX, aliensY
- pivotX = aliensX[0]
- bY, pivotY, aY = partition(pivotX, aliensY)
- bX, _, aX = partition(pivotY, aliensX)
- bX, bY = find_partners(bX, bY)
- aX, aY = find_partners(aX, aY)
- return [*bX, pivotX, *aX], [*bY, pivotY, *aY]
- def partition(pivot, aliens):
- b = []
- p = None
- a = []
- for alien in aliens:
- color = compare_aliens(pivot, alien)
- if color == "white":
- a.append(alien)
- elif color == "black":
- b.append(alien)
- else:
- p = alien
- return b, p, a
- def compare_aliens(alien_x, alien_y):
- if alien_x == alien_y:
- return "green"
- elif alien_x < alien_y:
- return "white"
- else:
- return "black"
- # Example usage
- alienX = [1, 5, 2, 4, 3, 8, 6, 7]
- alienY = [3, 7, 1, 8, 4, 5, 6, 2]
- partners = find_partners(alienX, alienY)
- print("Partners:", partners)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement