Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 70
Good morning! Here's your coding interview problem for today.

This problem was asked by Microsoft.

A number is considered perfect if its digits sum up to exactly 10.

Given a positive integer n, return the n-th perfect number.

For example, given 1, you should return 19. Given 2, you should return 28.

Pull request:
Day70
Resolves #149.

Patch:
diff --git a/README.md b/README.md
index 36da826..866c3b3 100644
--- a/README.md
+++ b/README.md
@@ -79,3 +79,4 @@ problems from
 * [Day 67](https://github.com/vaskoz/dailycodingproblem-go/issues/143)
 * [Day 68](https://github.com/vaskoz/dailycodingproblem-go/issues/145)
 * [Day 69](https://github.com/vaskoz/dailycodingproblem-go/issues/147)
+* [Day 70](https://github.com/vaskoz/dailycodingproblem-go/issues/149)
diff --git a/day70/problem.go b/day70/problem.go
new file mode 100644
index 0000000..2605753
--- /dev/null
+++ b/day70/problem.go
@@ -0,0 +1,24 @@
+package day70
+
+// PerfectNth returns the n-th perfect number.
+// A perfect number is one where the digits sum to 10.
+// A panic will happen if the argument is less than 1.
+func PerfectNth(n int) int {
+	if n < 1 {
+		panic("n must be greater than 0")
+	}
+	perfectNum := 10 // 10 is the seed value.
+	for n != 0 {
+		perfectNum += 9
+		digits := perfectNum
+		sum := 0
+		for digits != 0 {
+			sum += (digits % 10)
+			digits /= 10
+		}
+		if sum == 10 {
+			n--
+		}
+	}
+	return perfectNum
+}


Test patch:
diff --git a/day70/problem_test.go b/day70/problem_test.go
new file mode 100644
index 0000000..12b8ada
--- /dev/null
+++ b/day70/problem_test.go
@@ -0,0 +1,38 @@
+package day70
+
+import "testing"
+
+var testcases = []struct {
+	n, expected int
+}{
+	{1, 19},
+	{2, 28},
+	{10, 109},
+}
+
+func TestPerfectNth(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := PerfectNth(tc.n); result != tc.expected {
+			t.Errorf("Expected %v got %v", tc.expected, result)
+		}
+	}
+}
+
+func TestPerfectNthPanic(t *testing.T) {
+	t.Parallel()
+	defer func() {
+		if err := recover(); err == nil {
+			t.Errorf("Expected a panic for an argument less than 1")
+		}
+	}()
+	PerfectNth(0)
+}
+
+func BenchmarkPerfectNth(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			PerfectNth(tc.n)
+		}
+	}
+}