note: n, k changes randomly. you'll get different numbers.A robot is located at the top-left corner of a n * k grid.
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid.
How many possible unique paths are there?
i'm not gonna explain the solution(i'm terrible at explaining things). this is nothing but binomial coefficient. here's our little python code that does the job.
def factorial(n):
if n < 1:
return 1
return n*factorial(n-1)
def treasure(rows, cols):
r = rows-1
c = cols-1
return (factorial(r+c) / (factorial(r) * (factorial(c))))
i wonder why i didn't use lambda, it would end in two lines. that flu is killin' me...