17 lines
210 B
Ruby
17 lines
210 B
Ruby
|
def factorial(n)
|
||
|
i = 1
|
||
|
while (n > 0)
|
||
|
i *= n
|
||
|
n -= 1
|
||
|
end
|
||
|
i
|
||
|
end
|
||
|
|
||
|
def combination(n, k)
|
||
|
factorial(n) / (factorial(k) * factorial(n-k))
|
||
|
end
|
||
|
|
||
|
def lattice_paths(size)
|
||
|
combination(2*size, size)
|
||
|
end
|