0
Question in snail in the well proplem using Javascript I tried a lot of time but I couldn't,and what is the problem in this code
var c =0; var i=0; var depth = parseInt(readLine(), 10); function count() { //your code goes here while(c+7<depth){ c =c+5; i++; } while(c+7>=depth){ c =c+7; i++; } } count(); console.log(i);
10 ответов
+ 4
There's an another method.
When you don't want to use loop,
You can give it a try:
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
console.log(Math.round(depth/5))
}
But, in the hint, they told to use loop, so use loop.
In addition, just know it buddy😉, it will help you in any other coding 🙂
Happy learning 💐
+ 2
Can you post the challenge description or the link here.?
+ 2
Don't mark my answer as best yet, it has not even answered the main question.
+ 1
Brief Algorithm:
c = 0 // snail progress
d = 0 // count day
while(1)
d = d + 1 // increase the day
c = c + 7 // increase(climb) by 7 daytime
if c >= depth then // if the snail crosses the wall
print(day) // here's your answer
break // to kill infinite loop
c = c - 2 // decrease(slip) by 2 nighttime
+ 1
oops, typo it's 2
~LoneWolf thank you :)
0
I can't share but it is in conditional and loops in javascript course
0
The snail slips by 2 at night.
0
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.
0
OK what is wrong with my code
0
RKK Thanks I get it