def count_trees( grid, delta_col=3, delta_row=1 ):
    """
    Starting from position (0,0) of the grid, the goal is to
    count the trees by moving downwards with the slope described 
    by the delta arguments. 

    The grid is periodic in the horizontal direction (w.r.t columns) 
    and the counting is stopped when the last row of the grid is reached.
    """
    height = len(grid)
    width  = len(grid[0])
    count = 0
    row, col = 0, 0
    while row < height:
        count += grid[row][col] == '#'
        row += delta_row
        col = (col+delta_col) % width
    return count