Task

Print out the first   15   Catalan numbers by extracting them from Pascal's triangle.



See

   Catalan Numbers and the Pascal Triangle.     This method enables calculation of Catalan Numbers using only addition and subtraction.
   Catalan's Triangle for a Number Triangle that generates Catalan Numbers using only addition.
   Sequence A000108 on OEIS has a lot of information on Catalan Numbers.
Related Tasks

Pascal's triangle

INCLUDE "D2:REAL.ACT" ;from the Action! Tool Ki
 
DEFINE PTR="CARD"
DEFINE REALSIZE="6"
 
PTR FUNC GetItemAddr(PTR buf BYTE i)
RETURN (buf+REALSIZE*i)
 
PROC Main()
  DEFINE COUNT="15"
  BYTE ARRAY buf(102) ;(COUNT+2)*REALSIZE
  REAL POINTER r1,r2
  REAL c
  BYTE i,j
 
  Put(125) PutE() ;clear the screen
 
  r1=GetItemAddr(buf,1)
  IntToReal(1,r1)
 
  FOR i=1 TO COUNT
  DO
    j=i+1
    WHILE j>=2
    DO
      r1=GetItemAddr(buf,j)
      r2=GetItemAddr(buf,j-1)
      RealAdd(r1,r2,r1) ;t(j)==+t(j-1)
      j==-1
    OD
    r1=GetItemAddr(buf,i)
    r2=GetItemAddr(buf,i+1)
    RealAssign(r1,r2) ;t(i+1)=t(i)
 
    j=i+2
    WHILE j>=2
    DO
      r1=GetItemAddr(buf,j)
      r2=GetItemAddr(buf,j-1)
      RealAdd(r1,r2,r1) ;t(j)==+t(j-1)
      j==-1
    OD
    r1=GetItemAddr(buf,i)
    r2=GetItemAddr(buf,i+1)
    RealSub(r2,r1,c) ;c=t(i+1)-t(i)
    PrintF("C(%B)=",i) PrintRE(c)
  OD
RETURN