Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 184
Good morning! Here's your coding interview problem for today.

This problem was asked by Amazon.

Given n numbers, find the greatest common denominator between them.

For example, given the numbers `[42, 56, 14]`, return `14`.

Pull request description:
Day184
Resolves #378.

Patch:
diff --git a/README.md b/README.md
index 458c781..081950b 100644
--- a/README.md
+++ b/README.md
@@ -191,3 +191,4 @@ problems from
 * [Day 178](https://github.com/vaskoz/dailycodingproblem-go/issues/367)
 * [Day 179](https://github.com/vaskoz/dailycodingproblem-go/issues/371)
 * [Day 180](https://github.com/vaskoz/dailycodingproblem-go/issues/373)
+* [Day 184](https://github.com/vaskoz/dailycodingproblem-go/issues/378)
diff --git a/day184/problem.go b/day184/problem.go
new file mode 100644
index 0000000..2570219
--- /dev/null
+++ b/day184/problem.go
@@ -0,0 +1,21 @@
+package day184
+
+// GcdSlice returns the greatest common denominator
+// of all the values in the slice.
+func GcdSlice(nums []int) int {
+	if len(nums) == 0 {
+		return 0
+	}
+	result := nums[0]
+	for i := 1; i < len(nums); i++ {
+		result = gcd(nums[i], result)
+	}
+	return result
+}
+
+func gcd(a, b int) int {
+	if a == 0 {
+		return b
+	}
+	return gcd(b%a, a)
+}


Test patch:
diff --git a/day184/problem_test.go b/day184/problem_test.go
new file mode 100644
index 0000000..6138d82
--- /dev/null
+++ b/day184/problem_test.go
@@ -0,0 +1,30 @@
+package day184
+
+import "testing"
+
+var testcases = []struct {
+	nums     []int
+	expected int
+}{
+	{[]int{42, 56, 14}, 14},
+	{[]int{14}, 14},
+	{nil, 0},
+	{[]int{}, 0},
+}
+
+func TestGcdSlice(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := GcdSlice(tc.nums); result != tc.expected {
+			t.Errorf("Expected %v, got %v for input %v", tc.expected, result, tc.nums)
+		}
+	}
+}
+
+func BenchmarkGcdSlice(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			GcdSlice(tc.nums)
+		}
+	}
+}