- 2

Snail problem

Every day the snail crawls 7 feet up and every night it goes down 2 feet. How many days will it take for a snail to climb to the specified height?

15th Dec 2020, 4:25 AM
Alim Niyazov
Alim Niyazov - avatar
4 Answers
+ 5
Alim Niyazov Where is your attempts?
15th Dec 2020, 4:28 AM
A͢J
A͢J - avatar
+ 3
https://code.sololearn.com/cCpc2SlHCnBS/?ref=app Here's something similar using recursion
15th Dec 2020, 4:29 AM
Hima
Hima - avatar
+ 3
function climb() { var height = parseInt(readLine(), 10); let days = 0; if (height<= 0) return days; for (let i = 0; ; i -= 2) { i += 7; ++days; if (i >= height) break; i -= 2 } return days; } console.log(climb(days));
15th Dec 2020, 2:31 PM
Alim Niyazov
Alim Niyazov - avatar
+ 1
I just don't understand what's wrong with my code?
15th Dec 2020, 2:32 PM
Alim Niyazov
Alim Niyazov - avatar