! Amitabha lot
DECLARE EXTERNAL SUB construct
DIM w(5)
MAT READ w
DATA 3,4,5,1,2
SET WINDOW -1,5+1,32,-2    
LET p=0                    
FOR i=1 TO 5
   PLOT i,0;i,31
NEXT i
CALL construct(w,5,p)
END
! 
EXTERNAL SUB construct(w(),n,p)
IF n=1 THEN EXIT SUB
LET k=1
DO UNTIL w(k)=n
   LET k=k+1
LOOP
FOR i=k TO n-1
   LET p=p+1
   PLOT i,p;i+1,p
NEXT i
DIM v(5)
FOR i=1 TO k-1
   LET v(i)=w(i)
NEXT i
FOR i=k TO n-1
   LET v(i)=w(i+1)
NEXT i
CALL construct(v,n-1,p)
END SUB
