Factorial in Ruby

Example for versions Ruby 1.8.5

This example uses an iterative factorial definition.

def fact(n)
  (1..n).inject(1) {|a,b| a*b}
end

(0..16).each {|x| puts "#{x}! = #{fact(x)}"}