+ 1
The snail in the well
I passed it somehow but i just want to know why this code doesnt pass some tests function main() { var depth = parseInt(readLine(), 10); //your code goes here var y =0; for(var x=0;x<=depth;x+=7){ if(x<depth){ x-=2 y++ } } console.log(y) } The output is higher than the expected output by one For example in case 1 it should be 8 but the output is 9 I know its because it reduce x by 2 in the last night but it should not cause if you look when x is higher than depth it should not do the x-2 expression and should not do y++ either
2 Respostas
+ 2
First add 7 to x.
If it is not exceed depth then decrese by 2
else break.
+ 1
Thanks so the problem was that at first x was decreased by 2 without adding to 7