+ 2
o_O Why it doesn't return false only at (3, 4)?
I am attempting Danijel's challenge, I have my output of testCase1 matching the expected result except at position 4. The problem is that at (3, 4), it tests left obstacle at (2, 3) and passed.... So the ball moves to (3, 3) which it shouldn't The log results show that the other left obstacles are all detected without a problem. The concerned code snippet is at current line 252 to 255, as below: if( blocked(curI-1, curJ-1) ){ log("left blocked"); return false; } My attempt code : https://code.sololearn.com/W0O87WFcWEWK/?ref=app
7 Answers
+ 1
I must confess I don't understand your code yet.
But if I assume that your rows are horizontal like mine, I wonder why you would have to check for a road block that's not even in your row.
The question 1 is if below you is a block (otherwise you fall), and 2 and 3 would be if left and right is a block.
So in scenarios I can think of, you would test for (i+1, j), (i, j+1) and (i, j-1) (from your ball's current spot) and that was it.
(i+1 if your rows's index go up towards the bottom.)
But let me try to read a bit deeper into it. :)
+ 1
I misspoke in my earlier reply:
" if(blocked(curI, curJ-1)" and "if(blocked(curI-1, curJ)" will cause the first test case to pass but only "if(blocked(curI-1, curJ)" will invoke blocked(). In either case the other test case results stay the same.
0
if(blocked(curI, curJ-1)...
... instead seems to do the trick for the first example.
But other test cases also still failing.
0
but if not - 1 at row, means we check the one beside our obstacle?
0
Let me explain my index,
curI is the current row which the balls has not reached yet.
if it is a space, the ball falls down to current cell.
if it is blocked, we check the cell next to the ball, which is at curI - 1 level.
sure, thanks in advance for spending the time.
you can skip line 134 to 219, because decide() is based on the rejected assumption of "the ball stays in same direction all the way".
decideTwo() is my current implementation.
0
It appears that blocked() is never invoked from line 258 to check location (2,3) for left-sided obstacles.
https://code.sololearn.com/Wn3qrChLZU0v/#js
" if(blocked(curI, curJ-1)" or "if(blocked(curI-1, curJ)" will cause blocked() to be invoked at line 258, the first test case to pass plus the other test case results stay the same. Which makes this more perplexing.
0
But if not column-1, it is checking the cell which the ball is at which of course is space đ€