Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 158
Good morning! Here's your coding interview problem for today.

This problem was asked by Slack.

You are given an N by M matrix of 0s and 1s. Starting from the top left corner, how many ways are there to reach the bottom right corner?

You can only move right and down. 0 represents an empty space while 1 represents a wall you cannot walk through.

For example, given the following matrix:
```
[[0, 0, 1],
 [0, 0, 1],
 [1, 0, 0]]
```
Return two, as there are only two ways to get to the bottom right:

Right, down, down, right
Down, right, down, right

The top left corner and bottom right corner will always be 0.

Pull request description:
Day158
Resolves #329.

Patch:
diff --git a/README.md b/README.md
index 3cbba53..4d48781 100644
--- a/README.md
+++ b/README.md
@@ -168,3 +168,4 @@ problems from
 * [Day 155](https://github.com/vaskoz/dailycodingproblem-go/issues/322)
 * [Day 156](https://github.com/vaskoz/dailycodingproblem-go/issues/325)
 * [Day 157](https://github.com/vaskoz/dailycodingproblem-go/issues/327)
+* [Day 158](https://github.com/vaskoz/dailycodingproblem-go/issues/329)
diff --git a/day158/problem.go b/day158/problem.go
new file mode 100644
index 0000000..1d323f6
--- /dev/null
+++ b/day158/problem.go
@@ -0,0 +1,21 @@
+package day158
+
+// Maze is a matrix of walls and free space.
+// 1 - is a wall. 0 - is free space.
+type Maze [][]int
+
+// NumRoutesThruMaze returns the number of routes
+// from the upper-left to the bottom-right.
+func NumRoutesThruMaze(maze Maze) int {
+	return numRoutesThruMaze(maze, 0, 0)
+}
+
+func numRoutesThruMaze(maze Maze, row, col int) int {
+	if row >= len(maze) || col >= len(maze[0]) || maze[row][col] == 1 {
+		return 0
+	} else if row == len(maze)-1 && col == len(maze[row])-1 {
+		return 1
+	}
+	return numRoutesThruMaze(maze, row+1, col) +
+		numRoutesThruMaze(maze, row, col+1)
+}


Test patch:
diff --git a/day158/problem_test.go b/day158/problem_test.go
new file mode 100644
index 0000000..2beee44
--- /dev/null
+++ b/day158/problem_test.go
@@ -0,0 +1,31 @@
+package day158
+
+import "testing"
+
+var testcases = []struct {
+	maze     Maze
+	expected int
+}{
+	{[][]int{
+		{0, 0, 1},
+		{0, 0, 1},
+		{1, 0, 0},
+	}, 2},
+}
+
+func TestNumRoutesThruMaze(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := NumRoutesThruMaze(tc.maze); result != tc.expected {
+			t.Errorf("Expected %v got %v", tc.expected, result)
+		}
+	}
+}
+
+func BenchmarkNumRoutesThruMaze(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			NumRoutesThruMaze(tc.maze)
+		}
+	}
+}