Enumerating all possible sequences when we are given a set of N numbers and range for each of the N numbers
<p>Problem Statement:</p>

<p>We are given</p>

<ol>
<li><p>A set of T numbers S1, S2,....ST</p></li>
<li><p>An integer called Range</p></li>
</ol>

<p>This means S1 can take on (2*Range+1) values (S1-Range,S1-Range+1,...S1, S1+1,....S1+Range)
Similarly S2, ...ST can take on 2*Range+1 values</p>

<p>Problem 1:  How do I enumerate all the possible sequences?  I.e all the (2*Range-1)^T sequences (S1-Range,S2,...ST), S1-Range+1,S2,...ST), ....., (S1, S2-Range,S3,....ST) etc </p>

<p>Problem 2:  How do I only list the sequences whose sum is S1+S2+...+ST?</p>

<p>For problem 1:  The approach I am considering is to do a </p>

<pre><code>for (i=0; i&lt;pow(Range,T);i++)
{
   Sequences that can be derived from i are
   1. {Si + i mod pow(Range,i)}
   2. {Si - i mod pow(Range,i)}
}
</code></pre>

<p>Any other more elegant solution?</p>

<p>Also, any ideas for problem 2?</p>