Here is my solution to the Knights challenge. It is in simple J. The challenge is a more complex version of a Nice Knight APL puzzle that I wrote in about 1975. I still think in a loopy fashion. The script is attached.
knights '' ------------------------T--------┐ │11 12 13 14 15 16 17 18│W is 22 │ │21 22 23 24 25 26 27 28│B is 77 │ │31 32 33 34 35 36 37 38│W is 43 │ │41 42 43 44 45 46 47 48│B is 58 │ │51 52 53 54 55 56 57 58│W is 51 │ │61 62 63 64 65 66 67 68│B is 46 │ │71 72 73 74 75 76 77 78│W is 32 │ │81 82 83 84 85 86 87 88│B is 27 │ │ │W is 51 │ │ │B is 35 │ │ │W is 43 │ │ │B is 43 │ │ │10 moves│ L-----------------------+--------- Kip Murray made a big improvement over my control structures, so this is a better way to do what I did. ]CB=: (10*1+i.8)+/1+i.8 ]M=:_21 _19 _12 _8 8 12 19 21 ]((22+M)e.,CB)#22+M ]((77+M)e.,CB)#77+M n=: 13 :'((y+M)e.,CB)#y+M' ]n 22 ]n 77 r=: 13 :'(?#n y){n y' rm=: 13 :'r y' rm 54 knights=: 3 : 0 AM=:('W is ',":W=:22),:'B is ',":B=:77 T =: ? 2 while. -.W=B do. if. T do. AM=:AM,'W is ',":W=:rm W else. AM=:AM,'B is ',":B=:rm B end. T =: -.T end. CB;AM,(":_2+{.$AM),' moves' ) knights '' I am really looking for ways to write single sentences to achieve the final result. In my next post from Raul Miller, I'll show what I mean. Linda
---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm