s=0
for i in range(7):
for j in range(6):
for k in range(9):
if 1*i+2*j+3*k == 17:
s=s+i+j+k
else:
print(s) # prints a positive integer, not 0 as it had before
first problem solved
Is there a more elegant way to sum over a finite set of tuples where the components of those tuples are constrained by some system of equations & inequations, than manually writing out each condition given by those equations as if-else statements inside loops?
Ideally, eventually, I would like to make the length, n, of my tuples itself a variable, which I can then set at runtime. I would then like to sum a function, f(x(1),...,x(n)) over all n-tuples of nonnegative integers (x(1),...,x(n)) which are constrained in various ways, most commonly, sum of i*x(i) = m, for some given m (partitions of m).
Ultimately, the hypothetical goal is programming Gregory Egorychev's magnificent generalization of the Lagrange Inversion Formula (LIF) to systems of multiples equations & dependent variables.
Thanks for the two responses so far.