Quick actions

cmd+k|ctrl+k

Navigation

Languages

PE15

Snippet info

Language

Python

Visibility

public

Author

thanhtu250590

Created

2016-07-06T04:23:00Z

Updated

2016-07-18T15:46:40Z

def path_counter(x,y):
    
    path = {}
    #generate path[list] for matrix x*y
    path[x,y] = 0
    
    # matrix 0
    if(x==1 and y==1):
        return 0
    # matrix 1
    if(x==1 or y==1):
        return 1
        
    # path of the horizontal and vertical border
    for coor_x in range(x-1,0,-1):
        path[coor_x,y] = 1
    for coor_y in range(y-1,0,-1):
        path[x,coor_y] = 1
    # loop to fill path of all other note
    for coor_x in range(x-1,0,-1):
        for coor_y in range(y-1,0,-1):
            path[coor_x,coor_y] = path[coor_x+1,coor_y] + path[coor_x,coor_y+1]
    return path
path = path_counter(21,21)
print(path[1,1])
INFO