0
The snail in the well problem
I know I'm doing something really basic wrong but I've been looking at it for so long, I don't see it. It's a simple while loop. The 2 inputs for depth of the well is 42 and 128. If I set my variable day = 0, 42 works fine but, 128 does not. If I set my variable day = 1, 128 works but 42 does not. What am I doing wrong? var depth = 42/128; var prog = 0; var day = 1; while (prog < depth) { prog = (prog + 5); day ++; } console.log (day); }
7 Réponses
+ 3
you don't have to hardcode input: there will provided for you trough the parseInt(readline(),10) call...
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var climb = 2, days = 0;
do climb -= 2, ++days; while ((climb += 7)<depth);
console.log(days);
}
0
How can I do both test cases?
- 1
I have a problem with some entries like 42,32 the result is greater by one day.
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var d=0;
for(i=0;i<=depth;i+=7)
{
if(i>=depth)
break ;
i-=2;
d++;
}
console .log (d);
}
- 1
May Any one help my with this code?
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var d=0;
for(i=0;i<=depth;i+=7)
{
if(i>=depth)
break ;
i-=2;
d++;
}
console .log (d);
}
- 1
@Maram Al_Qadasi , Good code, just missing one or two bits.
See solution
https://www.sololearn.com/learning/eom-project/1024/979
- 1
day = 0;
while (depth>0) {
depth-=7;
day++;
if (depth>0) {depth+=2;}
}
console.log(day);
}
- 1
👍