Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. A = [1,3,5]
  2. B = [2,4,6]
  3.  
  4. A = [1,3,5]
  5. B = [2,4,6]
  6. stored = []
  7.  
  8. #Work out the maximum length of a valid subsequence
  9. max_length = len(B) + len(A) - (max(len(A), len(B)) - min(len(A), len(B)))
  10.  
  11. for x in range (2, max_length + 1, 2): #Incremenet in steps of 2
  12. for item in A: #Take each element in A
  13. for start_B in range(len(B) + 1): #Gets an index so a copy of B can be made
  14. new_A = A[:]
  15. new_B = B[start_B:] #Uses index to create copy of B starting from start_B
  16. output_array = []
  17. index = 0
  18. turnA = True
  19. while new_A or new_B:
  20. if output_array == []:
  21. output_array.append(item)
  22. new_A.remove(item)
  23. turnA = False
  24. if turnA and new_A:
  25. if new_A[0] > output_array[-1]:
  26. output_array.append(new_A[0])
  27. turnA = False
  28. new_A.pop(0)
  29. elif turnA == False and new_B:
  30. if new_B[0] > output_array[-1]:
  31. output_array.append(new_B[0])
  32. turnA = True
  33. new_B.pop(0)
  34. else:
  35. break
  36. if len(output_array) == x:
  37. if output_array not in stored:
  38. print(output_array)
  39. stored.append(output_array[:])
  40. output_array.pop()
  41. if turnA == False:
  42. turnA == True
  43. else:
  44. turnA = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement