Background: http://programmers.stackexchange.com/questions/281820/algorithms-for-allocating-n-balls-into-m-boxes I'm trying a using recursion to update an array; data Test; N = 14; M = 3; array boxes[4] boxes1-boxes4 (4*.); V = MyFun(N,M,boxes); run; proc fcmp outlib=Work.Functions.Test; function MyFun(N,M,boxes ) varargs; outargs boxes; if M = 1 then do; Total = 0; do i = 0 to N; if Func1(i) > Total then do; Total = Func1(i); boxes[1] = i; end; end; end; if M = 2 then do; Total = 0; do i = 0 to N; do j = 0 to N-i; if Func1(i) + Func2(j) > Total then do; Total = Func1(i) + Func2(j); boxes[1] = i; boxes[2] = j; end; end; end; end; if M = 3 then do; Total = 0; D = dim(boxes); array temp[1] / nosymbols; call dynamic_array(temp,D); do i = 0 to N; do j = 0 to min(i,N-i); Total_New = MyFun(i-j,M-1,temp) + Func3(j); if Total_New > Total then do; Total = Total_New; boxes[1] = temp[1]; boxes[2] = temp[2]; boxes[3] = j; end; end; end; end; return(Total); endsub; run; For M < 3, this works. But When M = 3, Total_New = MyFun(i-j,M-1,temp) + Func3(j); doesn't update the array temp. For M > 3, how can I automatically adjust Func3 to MyFun_for_that_M ? In fact, functions don't have the same prefix. Any hint is greatly appreciated.
... View more