+ 2

Can anyOne figure this out?

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

29th Jun 2022, 2:44 PM
Abolfazl Abbaspour
Abolfazl Abbaspour - avatar
9 Respuestas
+ 3
Yes, but what exactly do you need help with?
29th Jun 2022, 2:45 PM
Justice
Justice - avatar
+ 2
It's giving you the math in the task description. You wrote it out.
29th Jun 2022, 2:50 PM
Justice
Justice - avatar
0
This is The Hint 👇🏻 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.
29th Jun 2022, 2:45 PM
Abolfazl Abbaspour
Abolfazl Abbaspour - avatar
0
the Math 😅😁
29th Jun 2022, 2:46 PM
Abolfazl Abbaspour
Abolfazl Abbaspour - avatar
29th Jun 2022, 2:49 PM
Abolfazl Abbaspour
Abolfazl Abbaspour - avatar
0
the problem is i don’t know wrote what where Justice
29th Jun 2022, 2:51 PM
Abolfazl Abbaspour
Abolfazl Abbaspour - avatar
0
nothing
29th Jun 2022, 3:01 PM
Abolfazl Abbaspour
Abolfazl Abbaspour - avatar
0
You can try this as well n is the input 7x - 2(x - 1) = n x = (n - 2) / 5 result -> x + (x % 5 != 0)
29th Jun 2022, 9:24 PM
Мартин 😑🎵
Мартин 😑🎵 - avatar
0
i = 0; for (; depth > 0;) { i++; depth -= 7 if (depth > 0) { depth += 2 } } console.log(i);
30th Jun 2022, 1:39 PM
Hasitha Charaka
Hasitha Charaka - avatar