Handle a horizontal move. Handle a left move. Switch to state 'L'. |l -> OL Skip over the instruction stream, cells, inactive cursors and separators. Ll -> lL Lr -> rL Lu -> uL Ld -> dL L. -> .L L* -> *L L; -> ;L L[ -> [L Shift a cursor to the left. .LA -> A.L *LA -> A*L .LI -> I.L *LI -> I*L Skip a cursor if it can't move any further. ;LA -> ;AL [LA -> [AL ;LI -> ;IL [LI -> [IL At the end of the grid, reset. L] -> S] Handle a right move. Switch to state 'R'. |r -> OR Skip over the instruction stream, cells, inactive cursors and separators. Rl -> lR Rr -> rR Ru -> uR Rd -> dR R. -> .R R* -> *R R; -> ;R R[ -> [R Shift a cursor to the right. RA. -> .AR RA* -> *AR RI. -> .IR RI* -> *IR Block a right move if a cursor can't move any further. .A; -> A.; *A; -> A*; .A] -> A.] *A] -> A*] .I; -> I.; *I; -> I*; .I] -> I.] *I] -> I*] At the end of the grid, reset. R] -> S] Handle a vertical move. Handle an upward move. Switch to state 'U'. |u -> OU Skip over the instruction stream, cells, inactive cursors and separators. Ul -> lU Ur -> rU Uu -> uU Ud -> dU U. -> .U U* -> *U U; -> ;U U[ -> [U UI -> IU Select an active cursor, switch to state 'X'. UA -> XI Skip to the next inactive cursor. .X -> X. *X -> X* ;X -> X; Set the inactive cursor to active and reset. IX -> SA If you're at the start of the grid, switch to state 'E'. [X -> [E Seek to the nearest inactive cursor. E. -> .E E* -> *E E; -> ;E Set the inactive cursor to active and reset. EI -> SA Handle a downward move. Switch to state 'D'. |d -> OD Skip over the instruction stream, cells, inactive cursors and separators. Dl -> lD Dr -> rD Du -> uD Dd -> dD D. -> .D D* -> *D D; -> ;D D[ -> [D DI -> ID Select an active cursor, switch to state 'Y'. DA -> IY Skip to the next inactive cursor. Y. -> .Y Y* -> *Y Y; -> ;Y Set the inactive cursor to active and reset. YI -> SA If you're at the end of the grid, swtich to state 'F'. Y] -> F] Seek to the nearest inactive cursor. .F -> F. *F -> F* ;F -> F; Set the inactive cursor to active and reset. IF -> SA Handle a mark. Switch to state 'M'. |* -> OM Skip over the instruction stream, cells, inactive cursors and separators. Ml -> lM Mr -> rM Mu -> uM Md -> dM M. -> .M M* -> *M M; -> ;M M[ -> [M MI -> IM Select an active cursor, toggle the pixel under it and reset. MA. -> SA* MA* -> SA. Handle a reset. Skip to the start of the instruction stream. lS -> Sl rS -> Sr uS -> Su dS -> Sd .S -> S. *S -> S* ;S -> S; [S -> S[ AS -> SA IS -> SI Switch to state '|', ready to read another instruction. OS -> | Expected result: .*.*. ..*.. *...* .***. Expected result (in string form): |[.*.*I.;..*.I.;*...A*;.***I.;] ::=:: | r* rr* dl* dll* dr* r* r* ru* [ A.....; I.....; I.....; I.....; ]