0
Snail in the well problem
can someone tell me why this isn't working: function main() { var depth = parseInt(readLine(), 10); var rem = depth % 5; switch(rem) { case 0: console.log((depth-rem)/5); break; case 2: console.log((depth-rem)/5); break; case 1: console.log(((depth-rem)/5)+1); break; case 3: console.log(((depth-rem)/5)+1); break; case 4: console.log(((depth-rem)/5)+1); break; } //i'm getting one test case not working
4 Respostas
+ 3
You are overcomplicating this problem... It could be solved as easy as something like that:
function main() {
var depth = parseInt(readLine(), 10);
//your code goes her
var days = 0;
while (depth > 0){
days += 1;
depth -= 7;
if (depth <= 0)
break;
depth+= 2;
}
console.log(days)
}
+ 2
case 1:
console.log((depth-rem)/5);
break;
0
Very Simple
Take a look:
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var day=0;
var i;
for( i=0; day < depth; i++)
{
day += 7;
if(day >= depth)
{
i += 1;
break;
}
day -= 2;
}
console.log(i);
}