Module: Math

Defined in:
lib/small/math.rb

Class Method Summary collapse

Class Method Details

.fact(n) ⇒ Object Also known as: factorial



4
5
6
# File 'lib/small/math.rb', line 4

def fact(n)
  (1..n).inject(1) {|r,i| r*i}
end

.fib(n) ⇒ Object Also known as: fibanocci



9
10
11
# File 'lib/small/math.rb', line 9

def fib(n)
  n < 2 ? n : fib(n-1)+fib(n-2)
end