/* Recursive N-base Dimension Indexing (overflow-free) */ new; cls; x={0,0,0,0,0}; N=10; print x'; do while not x==(N-1); x=recNindex(x,N); print x'; endo; /* ** recNindex.txt - Recursive N-base Dimension Indexing. ** (C) Copyright 2005 Yosuke Amijima. All Rights Reserved. ** ** Purpose: Gets N-base index numbers for given dimension recursively ** without overflow problem. ** ** Format: x=recNindex(x,N); ** ** Input: x vector, dim x 1 of current N-base index vector ** ** N scalar, base number ** ** Output: x vector, dim x 1 of next N-base index vector ** ** Notice: You could start from x={0,0,0,0,0}; for example. */ proc recNindex(x,N); local dim,j; dim=rows(x); x[dim]=x[dim]+1; j=dim; do until j==0; if x[j]==N; x[j]=0; x[j-1]=x[j-1]+1; endif; j=j-1; endo; retp(x); endp;