
  '=================
  'PASCAL'S TRIANGLE
  '=================
  '
  '      1
  '     1 1
  '    1 2 1
  '   1 3 3 1
  '  1 4 6 4 1
  '
  'rows are numberes 1 to n.
  'row[1..n] contains base index to row data.
  'dat[1..m] contains all the data for each row going left to right indexed by j.
  'number of elements in each row equals the row index i.

  use console


  string pad(int v){
  ==================
  int n,p,q,r
  string m
  m=str(v)
  n=len(m)
  'return "    x   "
  p=8-n
  q=p>>1
  r=q
  if q+r<>p then q++ 'odd
  return space(q)+m+space(r)
  }

  % nq=10
  % mq=nq*nq
  'print mq cr

  sys row[nq]
  sys dat[mq]
  sys c,d,i,j,k
  string pp[nq]
  print "Pascal's Triangle:" cr cr
  string pr
  for i=1 to nq
    c++
    row[i]=c
    dat[c]=1
    pr+=pad dat[c]
    if i>1
      d=row[i-1]
    end if
    for j=2 to i-1
      c++
      dat[c]=dat[d]+dat[d+1]
      d++
      pr+=pad dat[c]
    next
    c++
    dat[c]=1
    if i>1 then pr+=pad 1
    k++
    pp[k]=pr
    pr=""
  next
  string pd
  int km=k-1
  j=1
  for i=1 to k
    pd=space(km*4) : km--
    print i tab j tab pd pp[i] cr
    j+=j
  next
  waitkey