Also, note that with that approach the result for input
n
actually corresponds to
n-1
, because you generate
visited points, not
steps. You would need to add an initial
Q
in the code, which will take the implicit input and add 1:
QJ4:!^Z^!Ys"@u@X=]vYm