Please Forward: Ruby Quiz Submission

From: ajwitte@gmail.com
Date: June 23, 2006 5:45:19 PM CDT
To: submission@rubyquiz.com
Subject: Please Forward: Ruby Quiz Submission

#!/usr/bin/env ruby

require 'enumerator'

class Array
  def show
    puts self.join(' ')
    self
  end
end

# Print a Pascal triangle of n rows
# and return the bottom-most row as an array.
def triangle(nrows)
  return [1].show if nrows <= 1
  previous = triangle(nrows-1).enum_for :each_cons, 2
  [1, previous.map {|a| a[0] + a[1] }, 1].flatten.show
end

triangle (ARGV[0] || 5).to_i

···

Begin forwarded message: