Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A = [1,3,5]
- B = [2,4,6]
- A = [1,3,5]
- B = [2,4,6]
- stored = []
- #Work out the maximum length of a valid subsequence
- max_length = len(B) + len(A) - (max(len(A), len(B)) - min(len(A), len(B)))
- for x in range (2, max_length + 1, 2): #Incremenet in steps of 2
- for item in A: #Take each element in A
- for start_B in range(len(B) + 1): #Gets an index so a copy of B can be made
- new_A = A[:]
- new_B = B[start_B:] #Uses index to create copy of B starting from start_B
- output_array = []
- index = 0
- turnA = True
- while new_A or new_B:
- if output_array == []:
- output_array.append(item)
- new_A.remove(item)
- turnA = False
- if turnA and new_A:
- if new_A[0] > output_array[-1]:
- output_array.append(new_A[0])
- turnA = False
- new_A.pop(0)
- elif turnA == False and new_B:
- if new_B[0] > output_array[-1]:
- output_array.append(new_B[0])
- turnA = True
- new_B.pop(0)
- else:
- break
- if len(output_array) == x:
- if output_array not in stored:
- print(output_array)
- stored.append(output_array[:])
- output_array.pop()
- if turnA == False:
- turnA == True
- else:
- turnA = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement