- 3

Hi guys I have tried the "snail in the well " but now I'm stuck . I need a hand .

function main() { var depth = parseInt(readLine(), 10); //your code goes here for(var i = 0 ; i <= depth; i += 5){ } if(depth % 5 == 0){ return depth/5 } else if((depth/5 - i/5) < 0.5 ){ return (i/5) } else if((depth/5 - i/5) > 0.5){ return i/5 + 1 } else{ } } console.log(main())

4th Mar 2021, 8:07 PM
Global Universe
Global Universe - avatar
17 Answers
+ 3
Hi! the depth variable is the distance that the snail must travel. during the day, it crawls 7 meters, at night it falls by two. you should create a variable where you should add 7 meters daily and compare it with depth. if the variable is greater than depth, then the snail crawled out. if not, the night comes and it falls 2 meters down
4th Mar 2021, 8:16 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Global Universe This is my code. Try it: function main() { var depth = parseInt(readLine(), 10); //your code goes here var climb = 7; var slip = 2; var day = 0; for(workdone=0;workdone<=depth;) { day = day+1; workdone = workdone+climb; if(workdone>=depth){ break; } workdone = workdone-slip; } console.log(day); }
5th Mar 2021, 12:22 AM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
0
What about the number of days ?
4th Mar 2021, 8:18 PM
Global Universe
Global Universe - avatar
0
and you don't need them
4th Mar 2021, 8:19 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
But that is supposed to be the output??
4th Mar 2021, 8:20 PM
Global Universe
Global Universe - avatar
0
no, the distance must be output (exit)
4th Mar 2021, 8:22 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Check it again output is days taken until it is out of the well
4th Mar 2021, 8:24 PM
Global Universe
Global Universe - avatar
0
Distance = length of the well
4th Mar 2021, 8:25 PM
Global Universe
Global Universe - avatar
0
yes, the distance is the length of the well. don't get hung up on it. I'll tell you even more directly. create your own personal variable, add 7 meters every day. and compare it with distance every day. if the variable is larger-voila, the snail is free. if not, lower it 2 meters down
4th Mar 2021, 8:38 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
I'm novice please tell me if the route I've taken hold promise😁
4th Mar 2021, 8:41 PM
Global Universe
Global Universe - avatar
0
your code is very confusing and not accurate. I've outlined the algorithm for you. try to implement it
4th Mar 2021, 8:44 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Ok thanks
4th Mar 2021, 8:44 PM
Global Universe
Global Universe - avatar
0
1.create your own personal variable, 2. add 7 meters every day. 3. compare it with distance every day. 4.if the variable is larger-voila, the snail is free -> end programm. 5. if not, lower it 2 meters down 6. new day is begin
4th Mar 2021, 8:46 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Thanks again
4th Mar 2021, 8:47 PM
Global Universe
Global Universe - avatar
0
- But that is supposed to be the output?? - And yes, in console.log() you must output number of days. Not main function
4th Mar 2021, 8:53 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
but the exit condition is distance. remember this
4th Mar 2021, 8:54 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Ok
4th Mar 2021, 8:55 PM
Global Universe
Global Universe - avatar