+ 3
Snail problem
Question: https://www.sololearn.com/post/801304/?ref=app My trial: https://code.sololearn.com/WbSEXApZmOi2/?ref=app Please give me hint where is the mistake 🥺 ( Hint only ) I wanna solve myself 🥺
13 Réponses
+ 3
You are 1st subtracting -2 next adding 7.
But it may lead wrong logic. &
Snail climbs 7 feet, if it is not the destination, then downs 2 feet. Otherwise it already done.
So after adding 7, break loop by condition checking, not after subtracting 2.
otherwise if for ex : input 31 but after adding 7, if it reached so subtracting 2 cause 31-2 cause loop another time. Increase k value 1 more.
So use if(i>=depth) break;
+ 3
Jayakrishna🇮🇳
It's showing 9 instead of 8
+ 2
Jayakrishna🇮🇳 yes...
But it's also not working
+ 2
You're welcome..
+ 2
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;
}
}
}
}
+ 1
Just add subtract according to the given description.. You are in reverse..
Oh you must subtract after condition check.
+ 1
Jayakrishna🇮🇳
Sorry, I couldn't understand
I add 7 in 'i', subtract with 2 and increase 'k' with 1 in each loop.
Then where is the mistake ?
+ 1
Jayakrishna🇮🇳
Still it's showing 9 instead of 8 in case of depth = 42
+ 1
Jayakrishna🇮🇳
Yes, it worked
Thank you
+ 1
console.log(Math.round(depth/5))
Most efficient way
0
var k = 0;
function main() {
// var depth = parseInt(readLine(), 10);
//your code goes here
for(let i = 0; i < 42; ){
k++
i+=7;
if(i >=42){
break;
}else{
i -= 2;
}
}
console.log(k)
}
main();
//check this code Prasant : The Nothing 😜🙈
0
Can someone tell me what I'm doing wrong in these codes:
{
var depth = parseInt(readLine(), 10);
//your code goes here
remainder = depth % 5;
if (remainder = 0) {
days = (depth/5);
}
else if (remainder = 1) {
days = ((depth/5)+1);
}
else if (remainder = 2) {
days = (depth/5);
}
else if (remainder = 3) {
days = ((depth/5)+1);
}
else if (remainder = 4) {
days = ((depth/5)+1);
}
}
//console.log (days);
0
With just one if statment , think out of the box , you dont need for loop at all :
if (depth%5<3){
var days=depth/5;
}else{
var days=(depth/5)+1;
}
console.log(parseInt(days));