<div dir="ltr"><div dir="ltr"><div>Moved to Coff, because it's about programming style, not history.</div><div dir="ltr"><br></div><div dir="ltr">> Perhaps I'm missing something? Clever arithmetic in the index<br>> calculation aside, this is semantically different than using an actual<br>> negative integer to index into an array? Moreover, if the intent is to<br>> start the sequence with 0, why set `fib(0)` to 1? How is this<br><div>> substantially different from the usual way of writing this:</div><div><br></div><div>I said the Fibonacci example was silly. Maybe you'll be more convinced by the binomial-coefficient program below. </div><div><br></div><div>The array of interest is fib. base is simply scaffolding and doesn't appear in the working code. You won't find the ith Fibonacci in base[i]; it's in fib(i). But fib(-1) exists. What's important is that the C convention of array indexes beginning at 0 has been circumvented.</div><div><br></div><div>I could be accused of subterfuge in depending on the semantics of static storage to initialize fib(-1) to zero. Subterfuge or not, it's customary C usage. The binomial-coefficient program relies on "out-of-bounds" zeros abutting two sides of a triangle.</div><div><br></div><div>int base[N][N+2];</div><div>#define binom(n,i) base[n][(i)+1]</div><div><br></div><div>void fill() {</div><div>    binom(0,0) = 1;</div><div>    for(n=1; n<N; n++)</div><div><span style="white-space:normal"><span style="white-space:pre">   </span>for(i=0; i<=n; i++)</span></div><div>            binom(n,i) = binom(n-1,i) + binom(n,i-1);</div><div>}</div><div><br></div><div>I think the offset algorithm above looks better than the more typical one below.</div><div>The two programs happen to have identical character counts.</div><div><br></div><div>int binom[N][N+1];</div><div><br></div><div>void fill() {</div><div>    for(n=0; n<N; n++) {</div><div>        binom[n][0] = 1;</div><div><span style="white-space:normal"><span style="white-space:pre">        </span>for(i=1; i<n; i++)</span></div><div>            binom[n][i] = binom[n-1][i] + binom[n][i-1];</div><div><span style="white-space:normal"><span style="white-space:pre">      </span>binom[n][n] = 1;</span></div><div>    }</div><div>}</div><div><br></div><div>Doug</div></div></div></div>