[seqfan] To walk on a grid
Eric Angelini
Eric.Angelini at kntv.be
Mon Aug 31 17:10:57 CEST 2015
Hello SeqFans,
Let's imagine an infinite grid of side-1 squares covering the plane.
On the floor of each square there is an arrow pointing to the North.
If I drop an integer N (say 27) on one of the squares, this is what
will happen :
(1) I will read the leftmost unread digit « d » of N (here, 2) and
turn the arrow to the right if « d » is even (this is the case
here with 2), else to the left (if « d » is odd);
(2) I will move « d » squares in the new direction (here, 2 squares
to the East);
(3) I will go back to instruction (1) as long as there are unread
digits in N.
Question:
For what N's does one go back to the starting square?
The integer 1111 is such an N, of course.
As are 2222, 3333, etc.
As is 1213311
or 1215331
or 1217351
or 1219371.
As is 202 - but this is tricky! -- Explanation for N = 202:
1) Turn the arrow of the origin square to the right (East) - as
the leftmost « 2 » is even;
2) Walk 2 squares in this direction;
3) Turn the arrow of the square to the right (South) - as « 0 »
is even;
4) Walk 0 square in this direction;
5) Turn the arrow of the (same!) square to the right (West) - as
the rightmost « 2 » is even;
6) Walk 2 squares in this direction: you're back on the origin
square.
Best,
É.
More information about the SeqFan
mailing list