>Hi All,
>
>I have a binomial tree structure. I want to get all the possible paths in this tree, I have been searching for an elegant way to do this. I'll explain with an example:
>
>A person starts with disability state 0, the following year he can get disabled and reaches state 1 or he stays active in the same state 0 (so there are two states in year 1 (2^time)). The following year 2 he can get disabled for the first time 0->1, or he stays active 0->0, or he gets better 1->0, or he disables more 1->2 (so 2^2 possibilities). And so on....
>
>I want to make a function that returns a array of strings of all possible paths given a specific duration, so :
>
>for year 0 : "0"
>for year 1: "01"
> : "00"
>for year 2: "000"
> "001"
> "012"
> "010"
>for year n: 2^n possibilities
>
>
>I have been trying to make a readable code for this, but with no success. Any ideas?
>
>Thanks beforehand.
DIMENSION aPath[1]
CLEAR
FOR k=1 TO AllPaths(@m.aPath,3)
? aPath[m.k]
NEXT
Procedure AllPaths(a,pathLen)
DIMENSION a[2^(m.pathLen+1)-1]
a[1]="0"
PRIVATE p,p1,y,state
p =1
p1 =2
FOR y=1 TO m.pathLen
FOR p=m.p TO m.p+2^(m.y-1)-1
state=ASC(RIGHT(a[m.p],1))
a[m.p1] =a[m.p]+CHR(MAX(m.state-1,48))
a[m.p1+1]=a[m.p]+CHR(m.state+1)
p1=m.p1+2
NEXT
NEXT
RETURN ALEN(a)
ENDPROC