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

 
Module CatalanNumbers {
      Def Integer count, t_row, size=31
      Dim triangle(1 to size, 1 to size)
 
      \\ call sub
      pascal_triangle(size, &triangle())
 
 
      Print "The first 15 Catalan numbers are"
      count = 1% : t_row = 2%
 
      Do {
            Print  Format$("{0:0:-3}:{1:0:-15}", count, triangle(t_row, t_row) - triangle(t_row +1, t_row -1))
            t_row++
            count++
      } Until count > 15
      End
 
      Sub pascal_triangle(rows As Integer, &Pas_tri())
          Local x=0%, y=0%
          For x = 1 To rows
              Pas_tri( 1%, x ) = 1@
              Pas_tri( x, 1% ) = 1@
          Next x
          if rows<2 then exit sub
          For x = 2 To rows-1
              For y = 2 To rows + 1 - x
                  Pas_tri(x, y) = pas_tri(x - 1 , y) + pas_tri(x, y - 1)
              Next y
          Next x
      End Sub
}
CatalanNumbers
 