Help:=proc(): print(`W(a,b), Wt(HorizA,VertA,w), BPb(HorizA,VertA,a,b)`):end: W:=proc(a,b) local S1,S2,i: option remember: if a=0 then RETURN({ [seq([0,i],i=0..b) ]}): elif b=0 then RETURN({ [seq([i,0],i=0..a) ]}): fi: S1:=W(a,b-1): S2:=W(a-1,b): {seq([op(S1[i]),[a,b]],i=1..nops(S1)), seq([op(S2[i]),[a,b]],i=1..nops(S2))}: end: #BPb(HorizA,VertA,a,b): The best path from [0,0] to [a,b] #given the Attraction Lists HorizA, VertA BPb:=proc(HorizA,VertA,a,b) end: #Wt(HorizA,VertB,w): Given the Horiz. and Vertical attraction #tables (given as lists of lists, #where HorizA[i][j] is #the number of attractions between [i-1,j-1] to [i-1,j] #where VertA[i][j] is #the number of attractions between [i-1,j-1] to [i,j-1] Wt:=proc(HorizA,VertA,w) local c,i,w1,pt1,pt2: if w=[[0,0]] then RETURN(0): fi: w1:=[op(1..nops(w)-1,w)]: c:=Wt(HorizA,VertA,w1): pt1:=w[nops(w)-1]: pt2:=w[nops(w)]: if pt1[2]=pt2[2] then RETURN(c+ HorizA[pt1[1]+1][pt1[2]+1]): elif pt1[1]=pt2[1] then RETURN(c+ VertA[pt1[1]+1][pt1[2]+1]): else print(`Something is wrong`): RETURN(FAIL): fi: end: