/* Recursive Ternary Dimension Indexing (This will not go into overflow problem.) */ new; cls; dim=5; x=zeros(dim,1); print x'; i=1; do while not x==2; x=rec3index(x); print x'; endo; /* ** rec3index.txt - Recursive Ternary Dimension Indexing. ** (C) Copyright 2005 Yosuke Amijima. All Rights Reserved. ** ** Purpose: Gets ternary index numbers for given dimension recursively ** without overflow problem. ** ** Format: x=rec3index(x); ** ** Input: x vector, dim x 1 of current ternary index vector ** ** ** Output: x vector, dim x 1 of next ternary index vector ** ** Notice: You could start from x={0,0,0,0,0}; for example. */ proc rec3index(x); local dim,j; dim=rows(x); x[dim]=x[dim]+1; j=dim; do until j==0; if x[j]==3; x[j]=0; x[j-1]=x[j-1]+1; endif; j=j-1; endo; retp(x); endp;