k.go 738 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package kata
  2. func GrowingPlantA(upSpeed, downSpeed, expected int) int {
  3. n := 1
  4. for reached := upSpeed; reached < expected; n++ {
  5. reached += upSpeed - downSpeed
  6. }
  7. return n
  8. }
  9. func GrowingPlantB(upSpeed, downSpeed, expected int) int {
  10. var n, reached int
  11. for n = 1; reached < expected; n++ {
  12. reached = upSpeed + (n-1)*(upSpeed-downSpeed)
  13. }
  14. return n - 1
  15. }
  16. func GrowingPlantC(upSpeed, downSpeed, expected int) int {
  17. n := 1
  18. for {
  19. reached := upSpeed + (n-1)*(upSpeed-downSpeed)
  20. if reached >= expected {
  21. break
  22. }
  23. n++
  24. }
  25. return n
  26. }
  27. func GrowingPlantD(upSpeed, downSpeed, expected int) int {
  28. return (expected - downSpeed) / (upSpeed - downSpeed)
  29. }
  30. func GrowingPlant(u, d, e int) int {
  31. return GrowingPlantD(u, d, e)
  32. }