+ 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

14th Jul 2022, 9:02 AM
Meysam
Meysam - avatar
2 Antworten
+ 2
First add 7 to x. If it is not exceed depth then decrese by 2 else break.
14th Jul 2022, 9:11 AM
Jayakrishna 🇮🇳
+ 1
Thanks so the problem was that at first x was decreased by 2 without adding to 7
14th Jul 2022, 9:23 AM
Meysam
Meysam - avatar