UVA 11507 Bender B. Rodríguez Problem

I could’nt think of any solution for this either than writing all the possible moves. Can anyone help me with it?