- 2
What is the code of snail in the well? I am confused. Please say me the code.
Please help me. function main() { var depth = parseInt(readLine(), 10); //your code goes here var i=7-2; do{ console.log(i); i++; } while(i<=10); }
4 Respostas
+ 5
Hi! First, please, show us your attempt!
+ 3
TD Gaming
Please show your attempts.
Someone will help you
+ 1
first, divide in time the snail's crawl up and its descent down. you have to think like a snail: during the day you crawl seven feet up and ONLY at night you go down two feet. and you don't use the depth variable in your program at all. depth is your specified number of feet of the length of the well. so do this: keep an independent record of the number of days passed. crawl 7 feet up during the day, then compare this distance with the total length of the well. if this distance is greater than or equal to the length of the well, then super! You're out! output the number of days spent to the console. if you don't crawl out of the well, the night begins - and you go down two feet. then a new day begins...
+ 1
function main() {
var depth = parseInt(readLine(), 10);
//tu código va aquí
var d = 0; // días
var c = 0; // caracol
while (c < depth) {
c += 7 - 2;
d += 1;
if (c > depth) {
if (c - 2 <= depth) {
console.log(d);
break;
}
else if (c > depth) {
console.log(d - 1);
break;
}
}
}
}