Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 212
Good morning! Here's your coding interview problem for today.

This problem was asked by Dropbox.

Spreadsheets often use this alphabetical encoding for its columns: "A", "B", "C", ..., "AA", "AB", ..., "ZZ", "AAA", "AAB", ....

Given a column number, return its alphabetical column id. For example, given 1, return "A". Given 27, return "AA".

Pull request description:
Day212
Resolves #436.

Patch:
diff --git a/README.md b/README.md
index 0b8b1da..e490863 100644
--- a/README.md
+++ b/README.md
@@ -221,3 +221,4 @@ problems from
 * [Day 208](https://github.com/vaskoz/dailycodingproblem-go/issues/427)
 * [Day 210](https://github.com/vaskoz/dailycodingproblem-go/issues/432)
 * [Day 211](https://github.com/vaskoz/dailycodingproblem-go/issues/434)
+* [Day 212](https://github.com/vaskoz/dailycodingproblem-go/issues/436)
diff --git a/day212/problem.go b/day212/problem.go
new file mode 100644
index 0000000..2170881
--- /dev/null
+++ b/day212/problem.go
@@ -0,0 +1,23 @@
+package day212
+
+// SpreadsheetColumnName returns the name of the column
+// based on the ordinal position.
+func SpreadsheetColumnName(pos int) string {
+	if pos < 1 {
+		return ""
+	}
+	pos--
+	var ans []rune
+	for pos >= 0 {
+		ans = append(ans, 'A'+rune(pos%26))
+		pos /= 26
+		if pos == 0 {
+			pos = -1
+		}
+		pos--
+	}
+	for i := 0; i < len(ans)/2; i++ {
+		ans[i], ans[len(ans)-1-i] = ans[len(ans)-1-i], ans[i]
+	}
+	return string(ans)
+}


Test patch:
diff --git a/day212/problem_test.go b/day212/problem_test.go
new file mode 100644
index 0000000..732b7ab
--- /dev/null
+++ b/day212/problem_test.go
@@ -0,0 +1,37 @@
+package day212
+
+import "testing"
+
+var testcases = []struct {
+	pos  int
+	cell string
+}{
+	{1, "A"},
+	{27, "AA"},
+	{52, "AZ"},
+	{53, "BA"},
+	{78, "BZ"},
+	{79, "CA"},
+	{677, "ZA"},
+	{702, "ZZ"},
+	{703, "AAA"},
+	{0, ""},
+	{-10, ""},
+}
+
+func TestSpreadsheetColumnName(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := SpreadsheetColumnName(tc.pos); result != tc.cell {
+			t.Errorf("Expected %v, got %v", tc.cell, result)
+		}
+	}
+}
+
+func BenchmarkSpreadsheetColumnName(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			SpreadsheetColumnName(tc.pos)
+		}
+	}
+}