I have two lists of numbers, for each member of the second I have to say if he is available using all the numbers of the first and putting '+' or '*' and as many ('') 'I want.
I can not change the order.
List1 can contain a maximum of 20 items between 1 and 100.
List2 can contain a maximum of 5 items between 1 and 20'000.
Example:
List1=[2 4 3 5] List2=[19 15 24] 19-> 2+(4*3)+5 YES 15 NO 24->2*(4+3+5) YES
Using brute force to process entries with List1 is greater than 10. It takes age.
edit: numbers are always positive.
edit: I find the max and min numbers that can be obtained from the list, and then I drop all the possibilities that have a goal outside this range, then I try to use all the others.
MAX=n1*n2*n3*....*ni if there are 1 thei r added to their smallest neighbour MIN=n1+n2+....+ni 1 excluded
However, it is not fast enough when the input is large (List1 is greater than 10 or the number in List2 is greater than 10,000)
source share