Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 221
Good morning! Here's your coding interview problem for today.

This problem was asked by Zillow.

Let's define a "sevenish" number to be one which is either a power of 7, or the sum of unique powers of 7. The first few sevenish numbers are 1, 7, 8, 49, and so on. Create an algorithm to find the nth sevenish number.

Pull request description:
Day221
Resolves #454.

Patch:
diff --git a/README.md b/README.md
index 5c0e2a2..58b8fe3 100644
--- a/README.md
+++ b/README.md
@@ -229,3 +229,4 @@ problems from
 * [Day 216](https://github.com/vaskoz/dailycodingproblem-go/issues/445)
 * [Day 217](https://github.com/vaskoz/dailycodingproblem-go/issues/447)
 * [Day 218](https://github.com/vaskoz/dailycodingproblem-go/issues/449)
+* [Day 221](https://github.com/vaskoz/dailycodingproblem-go/issues/454)
diff --git a/day221/problem.go b/day221/problem.go
new file mode 100644
index 0000000..3f7930d
--- /dev/null
+++ b/day221/problem.go
@@ -0,0 +1,27 @@
+package day221
+
+// SevenishNumber returns the n-th seven-ish number.
+// a "sevenish" number is one which is either a power of 7,
+// or the sum of unique powers of 7
+func SevenishNumber(n int) int {
+	if n < 1 {
+		return 0
+	}
+	sevens := 1
+	index := 1
+	nums := []int{1}
+	for index < n {
+		sevens *= 7
+		pos := len(nums)
+		nums = append(nums, sevens)
+		index++
+		for i := 0; i < pos; i++ {
+			if index >= n {
+				break
+			}
+			nums = append(nums, nums[i]+sevens)
+			index++
+		}
+	}
+	return nums[n-1]
+}


Test patch:
diff --git a/day221/problem_test.go b/day221/problem_test.go
new file mode 100644
index 0000000..9959728
--- /dev/null
+++ b/day221/problem_test.go
@@ -0,0 +1,37 @@
+package day221
+
+import "testing"
+
+var testcases = []struct {
+	n, expected int
+}{
+	{-1, 0},
+	{0, 0},
+	{1, 1},
+	{2, 7},
+	{3, 8},
+	{4, 49},
+	{5, 50},
+	{6, 56},
+	{7, 57},
+	{8, 343},
+	{9, 344},
+	{10, 350},
+}
+
+func TestSevenishNumber(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := SevenishNumber(tc.n); result != tc.expected {
+			t.Errorf("For n=%d, expected %d, got %d", tc.n, tc.expected, result)
+		}
+	}
+}
+
+func BenchmarkSevenishNumber(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			SevenishNumber(tc.n)
+		}
+	}
+}