Python, 48 48 47 bytes
f=lambda a,o=1:o<2ando>1or a and f(a[1:],len(a[0])-o)
A recursive function that accepts a list of strings and returns an empty list ([]
) if the input is valid or FalseTrue
if not.
How?
a
is our list of instructions.
o
starts off as 1
(,o=1
) and is a flag that indicates whether we are on an octagon (1
) or square (0
), this is updated for the next iteration by subtracting the current flag value from the current instruction length (len(a[0])-o
).
If we try to go diagonally from a square then o
becomes 2
(since \$2-0=2\$) and then the next iteration's evaluation of o<2o>1
causes a return value of FalseTrue
.
We drop the first (now executed) instruction from a
(a[1:]
) in order to perform the next iteration and if we find ourselves with an empty list the instructions were valid and andor a
causes this empty list to be returned.