Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 7
Good morning! Here's your coding interview problem for today.

This problem was asked by Facebook.

Given the mapping a = 1, b = 2, ... z = 26, and an encoded message, count the number of ways it can be decoded.

For example, the message '111' would give 3, since it could be decoded as 'aaa', 'ka', and 'ak'.

You can assume that the messages are decodable. For example, '001' is not allowed.

Pull request description:
Day7
Resolves #15 

Patch:
diff --git a/README.md b/README.md
index 764ff76..200854f 100644
--- a/README.md
+++ b/README.md
@@ -15,4 +15,5 @@ problems from
 * [Day 4](https://github.com/vaskoz/dailycodingproblem-go/issues/5)
 * [Day 5](https://github.com/vaskoz/dailycodingproblem-go/issues/9)
 * [Day 5 merge k sorted lists](https://github.com/vaskoz/dailycodingproblem-go/issues/11)
-
+* [Day 6](https://github.com/vaskoz/dailycodingproblem-go/issues/13)
+* [Day 7](https://github.com/vaskoz/dailycodingproblem-go/issues/15)
diff --git a/day7/problem.go b/day7/problem.go
new file mode 100644
index 0000000..4708f57
--- /dev/null
+++ b/day7/problem.go
@@ -0,0 +1,17 @@
+package day7
+
+// NumberOfDecodings calculates the number of possible decodings where
+// letters are encoding as a=1, b=2 ... z=26
+func NumberOfDecodings(str string) int {
+	if length := len(str); length == 0 || length == 1 {
+		return 1
+	}
+	var count int
+	if last := str[len(str)-1]; last > '0' && last <= '9' {
+		count = NumberOfDecodings(str[:len(str)-1])
+	}
+	if second := str[len(str)-2]; second == '1' || second == '2' && str[len(str)-1] < '7' {
+		count += NumberOfDecodings(str[:len(str)-2])
+	}
+	return count
+}


Test patch:
diff --git a/day7/problem_test.go b/day7/problem_test.go
new file mode 100644
index 0000000..472f85d
--- /dev/null
+++ b/day7/problem_test.go
@@ -0,0 +1,29 @@
+package day7
+
+import "testing"
+
+var testcases = []struct {
+	input    string
+	expected int
+}{
+	{"111", 3},
+	{"1111", 5},
+	{"2626", 4},
+	{"1234", 3},
+}
+
+func TestNumberOfDecodings(t *testing.T) {
+	for _, tc := range testcases {
+		if result := NumberOfDecodings(tc.input); result != tc.expected {
+			t.Errorf("For input %v, expected %v but got %v", tc.input, tc.expected, result)
+		}
+	}
+}
+
+func BenchmarkNumberOfDecodings(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			NumberOfDecodings(tc.input)
+		}
+	}
+}