I had one more try... to see how small I could make the code without golfing it. This is pretty straightforward, and I thought the direct calculation of the binomial coefficients (given a cached factorial) would be faster than array manipulations, but somehow it's slower: My earlier version: Gondor:~ mattmoss$ time ruby pascal.rb 666 > /dev/null real 0m9.303s user 0m8.619s sys 0m0.659s This version: Gondor:~ mattmoss$ time ruby pascal.rb 666 > /dev/null real 0m15.310s user 0m14.530s sys 0m0.719s Not sure why it should be so slow, but offhand (without knowing how to function-level profile) it seems nearly all the time is spent in binom(). $fact = Hash.new do |h, n| # The extra multiply allows us to use higher n before overflowing the stack. h[n] = (n < 2) ? 1 : n * (n - 1) * h[n - 2] end def binom(n, k) $fact[n] / ($fact[k] * $fact[n - k]) end def pascal n fw = binom(n - 1, n / 2).to_s.length # field width rw = (n * 2) * fw # row width (0...n).each do |i| # generate and print each row puts((0..i).map { |x| binom(i, x).to_s.center(2 * fw) }.join.center(rw)) end end pascal (ARGV[0] || 10).to_i