| #!/usr/local/bin/ruby -wKU # encoding: utf-8 # factorial # 10.fact class Integer def ! if self <= 1 1 else self * (self-1).! end end def fact (1..self).inject(:*) end def fact_inside "#{(1..self).to_a.reverse.join('×')} = #{self.fact}"
end def progress (1..self).inject(:+) end end p 10.! p 10.fact_inside p 10.progress |
Wednesday, June 04, 2008
Ruby Factorial
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment