Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools
- A=[10, 20, 30,40]
- B=[11,21,31,41]
- list_solutions = []
- for x in range (1,min(len(A),len(B))+1):
- newA = list(itertools.combinations(A,x))
- newB = list(itertools.combinations(B,x))
- for itemA in newA:
- for itemB in newB:
- to_print = True
- for index in range (min(len(itemA),len(itemB))):
- if itemA[index] >= itemB[index]:
- to_print = False
- break
- if to_print == True:
- list_solutions.append([itemA, itemB])
- #Print only valid solutions:
- for item in list_solutions:
- print_valid = True
- for index in range (len(item[0])):
- if item[0][index] >= item[1][index]:
- print_valid = False
- break
- if index >= 1:
- if item[0][index] <= item[1][index-1]:
- print_valid = False
- break
- if print_valid == True:
- for index in range (len(item[0])):
- print (item[0][index], item[1][index], sep = " ", end = " ")
- print ("")
- if print_valid == False:
- continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement