# performance tuning – Fastest way to compute the solution of this equation

I am looking for the solutions to the equation :
$$a_1+…+a_n =x$$
with
$$-3 leq a_iin mathbb {Z} leq 3 forall i$$
$$x in mathbb Z$$

Mathematica will get you the solutions eventually with ( x == tot, and varNbr==n) :

`Solutions(tot_, varNbr_) := Block({ unknowns= Symbol("a" <> ToString(#)) & /@ Range(varNbr) }, Solve(Total(unknowns) == tot&& ( -4 < # < 4) & /@ unknowns, unknowns, Integers) )`

but it’s very slow for big variable numbers. (try it with varNbr around 10 for example, not 1000).

Do you have faster solutions ?