From: Adam <skidooer@gmail.com>
Date: June 23, 2006 9:08:17 PM CDT
To: submission@rubyquiz.com
Subject: Please Forward: Ruby Quiz Submissionpp Pascal (#84)
-----------------------class Fixnum
def factorial
(1..self).to_a.inject(1) { |sum,i| sum *= i }
enddef choose(k)
self.factorial / (k.factorial * (self - k).factorial)
enddef times_for_collection
collection =
times { |i| collection << yield(i) }
collection
end
endclass Array
def to_triangle
collect { |row| ' ' * ((last.size - row.size) / 2) + row + "\n" }.join
end
endARGV[0].to_i.times_for_collection do |n|
(n + 1).times_for_collection do |k|
(k == 0 ? '%d' : '%6d') % (n > 1 ? (n - 1).choose(k - 1) + (n -
1).choose(k) : 1)
end.join
end.to_triangle.display
···
Begin forwarded message: