Question: Need some help debugging a diophantine problem please.

Given a positive integer k, another integer q >=2, the problem is to find the set of all positive integers {k_1,k_2, ...} such that

sum(k_iq^i,  i=0..infinity)  = k).
 

Note that for a given k this sum is always finite and so the solution set is always finite. Generally the output will consist of the array [k_0,k_1,k_2,...] but the output we seek is to print out only the terms [k_1,k_2,...] from this solution and then use this output later on for something else.

For example, given k=13, q=2 we should get the output 000, 100, 200, 300, 400, 500, 600, 010, 110, ......, (since we always eliminate k_0 from this list).  Right now (with the procedure below) it stops at [100]! I don't know why?!

q:=2;
sub1:= proc(i, k, f, A)
       if   i <= f then  A[i]:=A[i]+1; L:=convert(A, `list`);
                if sum(L[j]*q^j, j=1..f)<=  k then
                    print(L); A:=Array(L); sub1(1, k, f, A);
                 else A[i]:=0; sub1(i+1, k, f, A);
                fi;
       else print("DONE");
       fi;
  end;
lis := proc(k)
        local i, f, A;
         f:= floor(evalf(log(k)/log(q)));
         A:= Array([0$f]);
         sub1(1, k, f, A);
end;
k:=13;
lis(13);

"
 

Please Wait...