# Answer for https://stackoverflow.com/questions/65445073/number-of-ways-to-bottom-right-of-matrix-with-obstacles-with-any-size-skips-righ

rows = 4
cols = 3

matrix = """
    ...
    .*.
    ...
    ...
"""

M = [list(r) for r in matrix.split()]
print(M)

#(num_ways_here, cumulative_from_north, cumulative_from_east)
one = [None] * cols
two = [None] * cols

for i, r in enumerate(M):
  for j, c in enumerate(r):
    if (0, 0) == (i, j):
      two[j] = (1, 1, 1)
    elif M[i][j] == "*":
      two[j] = (0, 0, 0)
    elif i == 0:
      (c, n, e) = two[j-1]
      curr = e
      two[j] = (e, curr, e + curr)
    elif j == 0:
      (c, n, e) = one[j]
      curr = n
      two[j] = (curr, n + curr, curr)
    else:
      (cw, nw, ew) = two[j-1]
      (cn, nn, en) = one[j]
      curr = ew + nn
      two[j] = (curr, nn + curr, ew + curr)
  one = two
  two = [None] * cols
  print(one)

print(one[cols-1][0])