Class: Integer

Inherits:
Object show all
Defined in:
lib/basic/basic.rb

Instance Method Summary collapse

Instance Method Details

#factorial_iterativeObject Also known as: factorial


31
32
33
# File 'lib/basic/basic.rb', line 31

def factorial_iterative
  f = 1; for i in 1..self; f *= i; end; f
end

#factorial_recursiveObject


27
28
29
# File 'lib/basic/basic.rb', line 27

def factorial_recursive
  self <= 1 ? 1 : self * (self - 1).factorial
end