Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 91
Good morning! Here's your coding interview problem for today.

This problem was asked by Dropbox.

What does the below code snippet print out? How can we fix the anonymous functions to behave as we'd expect?
```
functions = []
for i in range(10):
    functions.append(lambda : i)

for f in functions:
    print(f())
```

Pull request description:
Day91
Resolves #192.

Patch:
diff --git a/README.md b/README.md
index 4b4cd17..dbbf95a 100644
--- a/README.md
+++ b/README.md
@@ -100,3 +100,4 @@ problems from
 * [Day 88](https://github.com/vaskoz/dailycodingproblem-go/issues/185)
 * [Day 89](https://github.com/vaskoz/dailycodingproblem-go/issues/187)
 * [Day 90](https://github.com/vaskoz/dailycodingproblem-go/issues/189)
+* [Day 91](https://github.com/vaskoz/dailycodingproblem-go/issues/192)
diff --git a/day91/problem.go b/day91/problem.go
new file mode 100644
index 0000000..aed4d2e
--- /dev/null
+++ b/day91/problem.go
@@ -0,0 +1,31 @@
+package day91
+
+// BadSnippet is given in the problem.
+func BadSnippet() []int {
+	funcs := make([]func() int, 9)
+	for i := 0; i < 9; i++ {
+		funcs[i] = func() int {
+			return i
+		}
+	}
+	result := make([]int, 9)
+	for i, f := range funcs {
+		result[i] = f()
+	}
+	return result
+}
+
+// FixedSnippet is how it should be written.
+func FixedSnippet() []int {
+	funcs := make([]func(int) int, 9)
+	for i := 0; i < 9; i++ {
+		funcs[i] = func(i int) int {
+			return i
+		}
+	}
+	result := make([]int, 9)
+	for i, f := range funcs {
+		result[i] = f(i)
+	}
+	return result
+}


Test patch:
diff --git a/day91/problem_test.go b/day91/problem_test.go
new file mode 100644
index 0000000..5c5f139
--- /dev/null
+++ b/day91/problem_test.go
@@ -0,0 +1,36 @@
+package day91
+
+import (
+	"reflect"
+	"testing"
+)
+
+func TestBadSnippet(t *testing.T) {
+	t.Parallel()
+	expected := []int{9, 9, 9, 9, 9, 9, 9, 9, 9}
+	result := BadSnippet()
+	if !reflect.DeepEqual(expected, result) {
+		t.Errorf("Expected %v got %v", expected, result)
+	}
+}
+
+func BenchmarkBadSnippet(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		BadSnippet()
+	}
+}
+
+func TestFixedSnippet(t *testing.T) {
+	t.Parallel()
+	expected := []int{0, 1, 2, 3, 4, 5, 6, 7, 8}
+	result := FixedSnippet()
+	if !reflect.DeepEqual(expected, result) {
+		t.Errorf("Expected %v got %v", expected, result)
+	}
+}
+
+func BenchmarkFixedSnippet(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		FixedSnippet()
+	}
+}