Wednesday, 29 June 2011

Project Euler problem 15

http://projecteuler.net/index.php?section=problems&id=15



def f (cache, posX, posY, sizeX, sizeY):

p=(posX, posY, sizeX, sizeY)
if p in cache:
return cache[p]

rt=0

# right
if posX+1 != sizeX:
rt=rt+f(cache, posX+1, posY, sizeX, sizeY)

# bottom
if posY+1 != sizeY:
rt=rt+f(cache, posX, posY+1, sizeX, sizeY)

# goal
if posX+1 == sizeX and posY+1 == sizeY:
rt=rt+1

cache[p]=rt

return rt

print (f({},0,0,21,21))

No comments:

Post a Comment