Advertisement
Guest User

Untitled

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