------art_7787_135548.1151550654957
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

After looking over my earlier answer, I realized that I had re-invented
String.center and had a number of excesses.  This one is a lot smaller but I
still feel I'm not using the language to its fullest.

JB

# pp_pascal.rb
# for details, see http://www.rubyquiz.com/quiz84.html

class Pascal
  def initialize( depth )
    @d  epth
    @p  [1]]
    1.upto(@d-1) do |row|
      @p[row]  1]
      1.upto(row-1) do |col|
        @p[row] << (@p[row-1][col-1] + @p[row-1][col])
      end
      @p[row] << 1
    end
  end
  def show
    # the middle entry in the bottom row will have the
    # most digits - use its length as the per-entry span
    span  @p[-1][(@d / 2).to_i].to_s.length) * 2
    width  d * span
    rows  ]
    @p.each do |p|
      ret  '
      p.each do |i|
        ret + .to_s.center(span)
      end
      rows << ret.center(width)
    end
    rows.join("\n")
  end
end

# default to 10 rows
rows  ARGV[0] || 10).to_i
p  ascal.new(rows)
puts p.show

------art_7787_135548.1151550654957--