- 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())
17 odpowiedzi
+ 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
+ 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);
}
0
What about the number of days ?
0
and you don't need them
0
But that is supposed to be the output??
0
no, the distance must be output (exit)
0
Check it again output is days taken until it is out of the well
0
Distance = length of the well
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
0
I'm novice please tell me if the route I've taken hold promise😁
0
your code is very confusing and not accurate. I've outlined the algorithm for you. try to implement it
0
Ok thanks
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
0
Thanks again
0
- But that is supposed to be the output??
- And yes, in console.log() you must output number of days. Not main function
0
but the exit condition is distance. remember this
0
Ok