12345678910111213141516171819202122232425262728293031323334353637 |
- 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)
- }
|