Question: Sums <= a given maximum with an odd number of distinct summands of a given list.

Hello
I would like to write a Maple program that gives me all possible sums >=  a given maximum maxsum and with and odd number q >= 3 of distinct summands from a given list. q can be 3, 5, 7, .. t, where t is odd and depends on L and max.

Example:
maxsum:=97, L := [9,15,21,25,27,33,35,39,45,49,51,55,57,63,65,69,75,77,81,85,87].

Here t= 3 and only q=3 is possible. In the final version of the program the list L and the maxsum will be much larger, so that the sums for every odd q =3, 5, 7, ..., t.

I tried to write a code for this basic case:

q := 3:
p := 91:
L := [9,15,21,25,27,33,35,39,45,49,51,55,57,63,65,69,75,77,81,85,87]:
M := []:

NestedLoops := proc(startIndex, remainingDepth, currentSum)
    local i;
    if remainingDepth = 0 then
        if currentSum <= p then
            M := [op(M), currentSum]:
        end if;
        return:
    end if;

    for i from startIndex to nops(L) - remainingDepth + 1 do
        NestedLoops(i + 1, remainingDepth - 1, currentSum + L[i]):
    od;
end proc:

NestedLoops(1, q, 0);
M;

The result ist "[]". What is wrong? How would be a correct and efficient version?

Thanks for helping me.

Please Wait...