0

Snail in the way. Resuelto

function main() { var depth = parseInt(readLine(), 10); var day = 1; for (i = 7; i <= depth; i=i+7){ if (i >= depth){ break; } i = i-2; day ++; } console.log(day); }

11th Sep 2022, 7:20 PM
Ana Laura Rivero
Ana Laura Rivero - avatar
3 Respostas
+ 3
Ana Laura Rivero / Jayakrishna🇮🇳 The Snail in the Well The snail climbs up 7 feet each day and slips back 2 feet each night. How many days will it take the snail to get out of a well with the given depth? Sample Input: 31 Sample Output: 6 Explanation: Let's break down the distance the snail covers each day: Day 1: 7-2=5 Day 2: 5+7-2=10 Day 3: 10+7-2=15 Day 4: 15+7-2=20 Day 5: 20+7-2=25 Day 6: 25+7=32 So, on Day 6 the snail will reach 32 feet and get out of the well at day, without slipping back that night. Hint: You can use a loop to calculate the distance the snail covers each day, and break the loop when it reaches the desired distance. 23 end of project module ( JavaScript )
12th Sep 2022, 1:25 AM
BroFar
BroFar - avatar
+ 2
BroFar yes sir. I know. But i think, there is no problem with code. And it seems advertising.. So asking clarity from OP.. Edit: Also I just checked it. It is working fine
12th Sep 2022, 8:29 AM
Jayakrishna 🇮🇳
+ 1
Your trouble with code?
11th Sep 2022, 8:06 PM
Jayakrishna 🇮🇳