there are six operator, and a logic table initial in b variable aa[b[j][i]] [aa[b[i][0:1]+b[i][2:3]
are just like vlookup to find output of each operator acting on first column and second column, second column and third column , first column and third column and searching a output columns which is result sum is 27*2 and record the path if succeed, it record the path and output any path which has result is 27*2 described before op1(op2(op3(op1(op2(),),op1(op2(),))), op1(op2(),)) there are two cases, first cases b are logic table later case are for six operators acting on the result column from previous result before recursive call def DFS(b, deep, maxx, sourceoperators, path): initlist = [] if deep > 0: print("deep=", deep) for aa,bb in itertools.combinations(sourceoperators, 2): print(aa,bb) if deep == maxx: finalresult = [] op1xy = [aa[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op1yz = [aa[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op1xz = [aa[b[i][0:1]+b[i][2:3]] for i in range(len(b))] op2xy = [bb[b[i][0:1]+b[i][1:2]] for i in range(len(b))] op2yz = [bb[b[i][1:2]+b[i][2:3]] for i in range(len(b))] op2xz = [bb[b[i][0:1]+b[i][2:3]] for i in range(len(b))] if sum(op1xy) == 54: path.append([(deep, aa, b, "xy")]) else: initlist.append(op1xy) if sum(op1yz) == 54: path.append([(deep, aa, b, "yz")]) else: initlist.append(op1yz) if sum(op1xz) == 54: path.append([(deep, aa, b, "xz")]) else: initlist.append(op1xz) if sum(op2xy) == 54: path.append([(deep, bb, b, "xy")]) else: initlist.append(op2xy) if sum(op2yz) == 54: path.append([(deep, bb, b, "yz")]) else: initlist.append(op2yz) if sum(op2xz) == 54: path.append([(deep, bb, b, "xz")]) else: initlist.append(op2xz) else: level = [] for j in range(len(b)): op1xy = [aa[b[j][i]] for i in range(len(b[j]))] op2xy = [bb[b[j][i]] for i in range(len(b[j]))] if sum(op1xy) == 54: path.append([(deep, aa, b[j], "xy")]) else: initlist.append(op1xy) if sum(op2xy) == 54: path.append([(deep, bb, b[j], "xy")]) else: initlist.append(op2xy) level.extend([op1xy, op2xy]) if deep == maxx: b = [] print("initlist=") print(len(initlist)) for aaa,bbb in itertools.combinations(initlist, 2): b.append([str(i)+str(j) for i,j in zip(aaa, bbb)]) if deep > 0: path2 = DFS(b, deep-1, maxx, sourceoperators, path) path.append(path2) return path path = [] mresult = DFS(b, 2, 2, mylist, path) On Friday, June 10, 2016 at 10:04:09 PM UTC+8, Michael Selik wrote: > On Thu, Jun 9, 2016, 9:11 PM Ho Yeung Lee <davidbenny2...@gmail.com> wrote: > > > input are these six operators, output is finding full column of 27 > > elements add together is 54 > > > > i got memory error when searching this, > > > > i have difficulty in understanding map reduce and transforming my program > > into map reduce problem > > > > Why do you think you need map-reduce? > > You'll need to explain the problem in more detail. Instead of talking about > operators and columns, what is the actual, real-world problem? > > > -- https://mail.python.org/mailman/listinfo/python-list