I copied everything into a script and then got this message when I tried to run it.
|control error | [7]else. | run=: dyad define |[-50] Run never gets defined but it's 7th line is else. . Your solution looks interesting, and I need more time to understand what you have done. Linda -----Original Message----- From: programming-boun...@jsoftware.com [mailto:programming-boun...@jsoftware.com] On Behalf Of Brian Schott Sent: Tuesday, May 01, 2012 9:05 PM To: Programming forum Subject: Re: [Jprogramming] Challenge 10 Knights Maypole Dance NB. knights.ijs NB. 4/20/12 NB. Geometrically creating 8 Knight moves NB. as if a positive first digit moves right NB. and a positive second digit moves up NB. on a chess table NB. with 0 0 as the bottom leftmost square k0=: _2]\1 2 2 1 x=: +/ . * NB. mattrix multiply r=: _2]\0 _1 1 0 NB. 90 degree rotation matrix k=: r (],x~&(_2&{.))^:3 k0 CP=: {@(,&<) NB. cross product cc=: CP ~i. 8 NB. c is $8 8 array of boxed values that knights can make c=: I. &.:>"1 cc *./@:((8&>*>:&0)@:+"1) each/ ;/k NB. testing one step B=: <6 6 W=: <1 1 NB. k (>@]+[{~(?@:#{])&>@({&c@])) B,W NB. this samples pairs of Knight @ B&W NB. m is the key verb NB. which takes two boxes with starting positions m=: k&(>@] ;/@:+ [ {~ (?@:# { ])&>@({&c@])) colorMatchQ=: +/@[ (= <.)@-:@+ +/@] NB. returns a Boolean NB.*run dyadic verb with boxed integer pairs between 0 & 7 NB. both integer pairs must be odd or both even sums NB. results: [WB][digit]+ NB. where digits count trials NB. global noun `all' contains trace NB. the `if.' clause is never used so is commented out NB. B run&> W NB. 6 6 run 1 1 run =: dyad define starts=. ? 2 NB. if 0 x starts, else y starts smoutput ' starts',~ ":>starts { x;y place=. starts|. x;y i=. 0 NB. count moves all=: i. 0 4 NB. trace NB. if both integer pairs are even sums, then colors match NB. and second knight wins always if. x colorMatchQ y do. winner=. starts{'WB' else. i=. 1 winner=. starts{'BW' all=: all,;place=. |. ({:>place);{.> m place end. while. ~:/place do. place=. m place i=. i+2 all=: all,;place end. winner,":i ) Note 'demos, but ymmv' B run&> W 1 1 starts B10 all 2 3 7 4 0 2 5 3 1 0 7 4 3 1 6 2 5 0 5 0 1 7 run 1 0 1 7 starts B21 all 3 6 3 1 2 4 2 3 0 5 1 5 1 3 2 3 3 2 0 4 1 3 1 2 3 2 3 3 4 4 4 5 2 3 5 7 1 5 3 6 3 6 8 8 ) Note 'More efficient simulations below' NB. but, W always wins in these simulations NB. so, 'BW'{~?2 must be used to randomize the winner NB. t contains the trace result NB. 2*#t=: m^:(~:/)^:a: B,W NB. 2*#t=: _1 ;\ m^:(~:/)^:a: B,W For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm