Could you tell me how to design an exhaustive algorithm for generating a new array by taking an element from each of the two arrays?

topic description

for example, the first group is: A B C D E and the second group is: 1 2 3 4

the numbers of the two groups are not necessarily symmetrical, and the number of the first group may be more or less than that of the second group. An example of the output result is as follows: A1B2C3D4 (only combination is not sorted), all possible results are required to be output

.

ask the boss for advice

-20180710 Update-

the description of the above problem is not clear, which is part of an auction algorithm. The elements in array 1 and 2 are deleted after they match, and the remaining elements continue to match. The number of new array elements produced is the smallest in array 1 and array 2. I wrote a program, but it didn"t feel good. I"m not good at programming. The output looks like this:

[[1,"A"], [2,"B"], [3,"C"], [4,"D"]]

[[1,"A"], [2,"B"], [3,"C"], [4,"E"]]

[[1,"A"], [2,"B"], [3,"D"], [4,"C"]

[[1,"A"], [2,"B"], [3,"D"], [4,"E"]]

[[1,"A"], [2,"B"], [3,"E"], [4,"C"]

[[1,"A"], [2,"B"], [3,"E"], [4,"D"]]

[[1,"A"], [2,"C"], [3,"B"], [4,"D"]]

[[1,"A"], [2,"C"], [3,"B"], [4,"E"]]

[[1,"A"], [2,"C"], [3,"D"], [4,"B"]]

[[1,"A"], [2,"C"], [3,"D"], [4,"E"]]

[[1,"A"], [2,"C"], [3,"E"], [4,"B"]]

[[1,"A"], [2,"C"], [3,"E"], [4,"D"]]

[[1,"A"], [2,"D"], [3,"B"], [4,"C"]]

[[1,"A"], [2,"D"], [3,"B"], [4,"E"]]

[[1,"A"], [2,"D"], [3,"C"], [4,"B"]]

[[1,"A"], [2,"D"], [3,"C"], [4,"E"]]

[[1,"A"], [2,"D"], [3,"E"], [4,"B"]]

[[1,"A"], [2,"D"], [3,"E"], [4,"C"]]

[[1,"A"], [2,"E"], [3,"B"], [4,"C"]

[[1,"A"], [2,"E"], [3,"B"], [4,"D"]]

[[1,"A"], [2,"E"], [3,"C"], [4,"B"]]

[[1,"A"], [2,"E"], [3,"C"], [4,"D"]]

[[1,"A"], [2,"E"], [3,"D"], [4,"B"]]

[[1,"A"], [2,"E"], [3,"D"], [4,"C"]]

[[1,"B"], [2,"A"], [3,"C"], [4,"D"]]

[[1,"B"], [2,"A"], [3,"C"], [4,"E"]]

[[1,"B"], [2,"A"], [3,"D"], [4,"C"]

[[1,"B"], [2,"A"], [3,"D"], [4,"E"]

[[1,"B"], [2,"A"], [3,"E"], [4,"C"]

[[1,"B"], [2,"A"], [3,"E"], [4,"D"]]

[[1,"B"], [2,"C"], [3,"A"], [4,"D"]]

[[1,"B"], [2,"C"], [3,"A"], [4,"E"]

[[1,"B"], [2,"C"], [3,"D"], [4,"A"]

[[1,"B"], [2,"C"], [3,"D"], [4,"E"]]

[[1,"B"], [2,"C"], [3,"E"], [4,"A"]]

[[1,"B"], [2,"C"], [3,"E"], [4,"D"]]

[[1,"B"], [2,"D"], [3,"A"], [4,"C"]

[[1,"B"], [2,"D"], [3,"A"], [4,"E"]]

[[1,"B"], [2,"D"], [3,"C"], [4,"A"]]

[[1,"B"], [2,"D"], [3,"C"], [4,"E"]]

[[1,"B"], [2,"D"], [3,"E"], [4,"A"]]

[[1,"B"], [2,"D"], [3,"E"], [4,"C"]]

[[1,"B"], [2,"E"], [3,"A"], [4,"C"]]

[[1,"B"], [2,"E"], [3,"A"], [4,"D"]]

[[1,"B"], [2,"E"], [3,"C"], [4,"A"]]

[[1,"B"], [2,"E"], [3,"C"], [4,"D"]]

[[1,"B"], [2,"E"], [3,"D"], [4,"A"]]

[[1,"B"], [2,"E"], [3,"D"], [4,"C"]]

[[1,"C"], [2,"A"], [3,"B"], [4,"D"]]

[[1,"C"], [2,"A"], [3,"B"], [4,"E"]]

[[1,"C"], [2,"A"], [3,"D"], [4,"B"]]

[[1,"C"], [2,"A"], [3,"D"], [4,"E"]]

[[1,"C"], [2,"A"], [3,"E"], [4,"B"]]

[[1,"C"], [2,"A"], [3,"E"], [4,"D"]]

[[1,"C"], [2,"B"], [3,"A"], [4,"D"]]

. Omit

sources of topics and their own ideas

none

what result do you expect? What is the error message actually seen?

look forward to seeing useful algorithms



python

import itertools
def main():
    list1 = ['A', 'B', 'C', 'D','E']
    list2 = [1,2,3,4]
    result = itertools.permutations(list1, 4)
    newlist = []
    for item in result:
        newlist.append(list(item))
    newnewlist = []
    for item in newlist:
        item[0] = [list2[0],item[0]]
        item[1] = [list2[1], item[1]]
        item[2] = [list2[2], item[2]]
        item[3] = [list2[3], item[3]]
    for item in newlist:
        print(item)
if __name__ == '__main__':
    main()
Menu