jasser

55 Reputation

3 Badges

2 years, 18 days

MaplePrimes Activity


These are questions asked by jasser

Hello

I have programs below for the cases n=3 and n=4. If n is increasing by 1, then there is one loop more. As you can see, that additional loop has always the structure:

x[i+1] from ceil(((n-2)*24-d[i])/(n-i)) to x[i]

whereas d[i] is the sum of the values of x before.

Now I want to write "nequaln":=proc(k), which goes through all the values for n from 3 to k and produces a list [a_3,a_4,a_5,...,a_n].

I guess that I need to program a kind of dynamical loop, but I failed completely. May someone help me? That would be very kind.

 

nequal3:=proc()
    local u,v,a_3;
    a_3:=0;
    for u from ceil((3-2)*24/(3-0)) to (3-2)*24-3+1 do
        for v from ceil(((3-2)*24-u)/(3-1)) to u do
            if (3-2)*24-u-v>=1 then
                a_3:=a_3+1;
            end if;
        end do;
    end do;
    print(a_3);
end proc:

 

nequal4:=proc()
    local u,v,w,a_4;
    a_4:=0;
    for u from ceil((4-2)*24/(4-0)) to (4-2)*24-4+1 do
        for v from ceil(((4-2)*24-u)/(4-1)) to u do
            for w from ceil(((4-2)*24-u-v)/(4-2)) to v do
                if (4-2)*24-u-v-w>=1 then
                    a_4:=a_4+1;
                end if;
            end do;
        end do;
    end do;
    print(a_4);
end proc:

Hello

I have a list with n positive integer numbers and a positive integer k.

I would like to write a Malple programm, that calculates, in how many ways k can be written as a sum of numbers in the list.

Easy examles: let the list be [2,3,6,9].

k=9 can be written in 4 ways: 9=9, 9=6+3, 9=3+3+3, 9=3+2+2+2. The result therefore shoud be 4.

k=8 can be written in 3 ways: 8=6+2, 8=3+3+2, 8=2+2+2+2. The result therefore shoud be 3.

Thank you very much your help!

1 2 Page 2 of 2