Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 275
Good morning! Here's your coding interview problem for today.

This problem was asked by Epic.

The "look and say" sequence is defined as follows: beginning with the term 1, each subsequent term visually describes the digits appearing in the previous term. The first few terms are as follows:
```
1
11
21
1211
111221
```
As an example, the fourth term is `1211`, since the third term consists of one `2` and one `1`.

Given an integer `N`, print the Nth term of this sequence.

Pull request description:
Day275
Resolves #560.

Patch:
diff --git a/README.md b/README.md
index e24f75b..ea8ce27 100644
--- a/README.md
+++ b/README.md
@@ -281,6 +281,7 @@ problems from
 * [Day 271](https://github.com/vaskoz/dailycodingproblem-go/issues/553)
 * [Day 272](https://github.com/vaskoz/dailycodingproblem-go/issues/555)
 * [Day 273](https://github.com/vaskoz/dailycodingproblem-go/issues/556)
+* [Day 275](https://github.com/vaskoz/dailycodingproblem-go/issues/560)
 * [Day 277](https://github.com/vaskoz/dailycodingproblem-go/issues/563)
 * [Day 278](https://github.com/vaskoz/dailycodingproblem-go/issues/565)
 * [Day 279](https://github.com/vaskoz/dailycodingproblem-go/issues/566)
diff --git a/day275/problem.go b/day275/problem.go
new file mode 100644
index 0000000..97d3b75
--- /dev/null
+++ b/day275/problem.go
@@ -0,0 +1,34 @@
+package day275
+
+import (
+	"fmt"
+	"strings"
+)
+
+func LookAndSay(n int) string {
+	if n < 1 {
+		panic("look and say number must be 1 or greater")
+	}
+	start := "1"
+	for i := 1; i < n; i++ {
+		var parts []string
+		var c rune
+		count := 0
+		for i, r := range start {
+			switch {
+			case i == 0:
+				c = r
+				count = 1
+			case c != r:
+				parts = append(parts, fmt.Sprintf("%d%s", count, string(c)))
+				c = r
+				count = 1
+			default:
+				count++
+			}
+		}
+		parts = append(parts, fmt.Sprintf("%d%s", count, string(c)))
+		start = strings.Join(parts, "")
+	}
+	return start
+}


Test patch:
diff --git a/day275/problem_test.go b/day275/problem_test.go
new file mode 100644
index 0000000..a24460b
--- /dev/null
+++ b/day275/problem_test.go
@@ -0,0 +1,45 @@
+package day275
+
+import "testing"
+
+// nolint
+var testcases = []struct {
+	n      int
+	result string
+}{
+	{1, "1"},
+	{2, "11"},
+	{3, "21"},
+	{4, "1211"},
+	{5, "111221"},
+	{6, "312211"},
+	{7, "13112221"},
+	{8, "1113213211"},
+}
+
+func TestLookAndSay(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := LookAndSay(tc.n); result != tc.result {
+			t.Errorf("Expected %v, got %v", tc.result, result)
+		}
+	}
+}
+
+func TestLookAndSayBadInput(t *testing.T) {
+	t.Parallel()
+	defer func() {
+		if err := recover(); err == nil {
+			t.Errorf("Expected a panic for input <1")
+		}
+	}()
+	LookAndSay(0)
+}
+
+func BenchmarkLookAndSay(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			LookAndSay(tc.n)
+		}
+	}
+}