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

3rd Oct 2021, 9:28 PM
Betty Chou
Betty Chou - avatar
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) }
3rd Oct 2021, 10:36 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
3rd Oct 2021, 9:56 PM
Simon Sauter
Simon Sauter - avatar
+ 2
case 1: console.log((depth-rem)/5); break;
4th Oct 2021, 8:05 AM
Simba
Simba - avatar
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); }
8th Oct 2021, 8:53 PM
Ben
Ben - avatar