Thanks @JorgeVS! Your pointer to read comments helped nailing the problem. But I must say, it is peculiar to take coder's own encode method and use it to feed in decoding.
the 0 here is the value under the pointer, not the "address of the pointer in the tape". So if '[' was encountered at 0, the value under the pointer IS 0 and you effectively move forward in any case.
As per the description it says, ']' - Jump back to matching [ (if value at current cell is nonzero). The statement in bracket 'if value at current cell is nonzero' is not correct. If we encounter ']' we need to always return back to matching '['.
Consider a scenario where matching '[' was encountered at 0 and current pointer is at non zero it needs to move forward.
Thanks @JorgeVS! Your pointer to read comments helped nailing the problem. But I must say, it is peculiar to take coder's own encode method and use it to feed in decoding.
Hey @JorgeVS, I am too at the same issue. Any pointers what am I missing?
you're wrong:
the 0 here is the value under the pointer, not the "address of the pointer in the tape". So
if '[' was encountered at 0
, the value under the pointer IS 0 and you effectively move forward in any case.As per the description it says, ']' - Jump back to matching [ (if value at current cell is nonzero). The statement in bracket 'if value at current cell is nonzero' is not correct. If we encounter ']' we need to always return back to matching '['.
Consider a scenario where matching '[' was encountered at 0 and current pointer is at non zero it needs to move forward.
When splicing, it will change the original array and that in my opinion is a negative side effect of the function.
This comment is hidden because it contains spoiler information about the solution