Browse Source

K7 growing plants

Frederic G. MARAND 4 years ago
parent
commit
41f28aebb7

+ 11 - 0
go/.idea/runConfigurations/k7_growing_plant.xml

@@ -0,0 +1,11 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="k7 growing plant" type="GoTestRunConfiguration" factoryName="Go Test">
+    <module name="codewars" />
+    <working_directory value="$PROJECT_DIR$/" />
+    <go_parameters value="-i" />
+    <framework value="gotest" />
+    <kind value="PACKAGE" />
+    <package value="code.osinet.fr/fgm/codewars/kyu7/simple_fun_74_growing_plant" />
+    <method v="2" />
+  </configuration>
+</component>

+ 2 - 0
go/go.sum

@@ -1,5 +1,6 @@
 github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
+github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
 github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
 github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
@@ -10,6 +11,7 @@ github.com/onsi/gomega v1.8.1 h1:C5Dqfs/LeauYDX0jJXIe2SWmwCbGzx9yF8C8xy3Lh34=
 github.com/onsi/gomega v1.8.1/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
 golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
 golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
 golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

+ 37 - 0
go/kyu7/simple_fun_74_growing_plant/k.go

@@ -0,0 +1,37 @@
+package kata
+
+func GrowingPlantA(upSpeed, downSpeed, expected int) int {
+	n := 1
+	for reached := upSpeed; reached < expected; n++ {
+		reached += upSpeed - downSpeed
+	}
+	return n
+}
+
+func GrowingPlantB(upSpeed, downSpeed, expected int) int {
+	var n, reached int
+	for n = 1; reached < expected; n++ {
+		reached = upSpeed + (n-1)*(upSpeed-downSpeed)
+	}
+	return n - 1
+}
+
+func GrowingPlantC(upSpeed, downSpeed, expected int) int {
+	n := 1
+	for {
+		reached := upSpeed + (n-1)*(upSpeed-downSpeed)
+		if reached >= expected {
+			break
+		}
+		n++
+	}
+	return n
+}
+
+func GrowingPlantD(upSpeed, downSpeed, expected int) int {
+	return (expected - downSpeed) / (upSpeed - downSpeed)
+}
+
+func GrowingPlant(u, d, e int) int {
+	return GrowingPlantD(u, d, e)
+}

+ 16 - 0
go/kyu7/simple_fun_74_growing_plant/k_test.go

@@ -0,0 +1,16 @@
+package kata_test
+
+import (
+	. "github.com/onsi/ginkgo"
+	. "github.com/onsi/gomega"
+
+	. "code.osinet.fr/fgm/codewars/kyu7/simple_fun_74_growing_plant"
+)
+
+var _ = Describe("Basic tests", func() {
+	//It("GrowingPlant(100, 10, 50)", func() { Expect(GrowingPlant(100, 10, 50)).To(Equal(1)) })
+	//It("GrowingPlant(100, 10, 910)", func() { Expect(GrowingPlant(100, 10, 910)).To(Equal(10)) })
+	It("GrowingPlant(10, 9, 4)", func() { Expect(GrowingPlant(10, 9, 4)).To(Equal(1)) })
+	It("GrowingPlant(5, 2, 5)", func() { Expect(GrowingPlant(5, 2, 5)).To(Equal(1)) })
+	It("GrowingPlant(5, 2, 6)", func() { Expect(GrowingPlant(5, 2, 6)).To(Equal(2)) })
+})

+ 13 - 0
go/kyu7/simple_fun_74_growing_plant/simple_fun_74_growing_plant_suite_test.go

@@ -0,0 +1,13 @@
+package kata_test
+
+import (
+	"testing"
+
+	. "github.com/onsi/ginkgo"
+	. "github.com/onsi/gomega"
+)
+
+func TestSimpleFun74GrowingPlant(t *testing.T) {
+	RegisterFailHandler(Fail)
+	RunSpecs(t, "SimpleFun74GrowingPlant Suite")
+}