3 of 3 deleted 242 characters in body; edited title

Algorithm for generate all solutions to a linear Diophantine equation

Consider the linear Diophantine equation of the form: $$\sum_{i=1}^{k}a_ix_i=n.$$ My goal is to list all the non-negative solutions to this equation. I wrote the following recursive algorithm, but I am not sure if it is the most efficient way to build the solutions. Here is the current version:

def recsolve(n, L, cursol, result = []):
if len(L) == 1:
ak = L[0]
if n%ak == 0:
result.append(cursol + [n//ak])
return

else:
a1 = L[0]
end = math.floor(n/a1)
for k in range(0, end + 1):
recsolve(n-k*a1,L[1:], cursol + [k],result)

result = []
n = 5
L = [1,2,3]
recsolve(n, L, [], result)
print(result, "; Number of solutions:", len(result))


I would be grateful if someone could suggest more efficient approaches to finding all solutions to a linear Diophantine equation.