Ah, gotcha -- thanks! -- Raul
On Tue, Jan 11, 2022 at 11:23 AM 'Michael Day' via Programming <[email protected]> wrote: > > I think it's easier to post my code than to try answering your question. > I've run successfully this in a new session, so I think it's > self-contained. > > Apologies for the verbose code - it's as I wrote it, and I haven't > attempted > to polish it for presentation here. The function "part2" , not shown here, > was the one I wrote before I remembered there were three throws for > each turn! I would have preferred to deal with both players in a double- > go, but gave up. I do of course realise that there's a lot of > reduplicated > code for player 2 - it would have been neater to move the code to an > ecternal function, but I didn't! > > Here it is - I hope it's not too opaque. > > m10 =: 10&|&.<: NB. modulo function for origin 1 > > die3 =: ~. /:~,(1 2 3 +/])^:2 ]1 2 3 > ctdie3 =: #/.~/:~,(1 2 3 +/])^:2 ]1 2 3 > > part2a =: 3 : 0 > 21 part2a y > : > cts =. 1 $ 1 > 'pos1 pos2' =. 2 1 $ y > 'scr1 scr2' =. 2 1 $ 0 > tgt =. x > wins =. 0 0 > turns=. 0 > ndie3=. # die3 > while. #cts do. > NB. player 1 > turns =. >: turns > pos1 =. m10 , pos1 +/ die3 > cts =. ,cts <.@*/ ctdie3 > scr1 =. pos1 + ndie3 # scr1 > pscr =. pos1,. scr1,. ndie3#pos2,. scr2 > cts =. pscr +//. cts > 'pos1 scr1 pos2 scr2' =. |: pscr =. ~. pscr > if. +/ win1=. tgt <: scr1 do. > i1 =. I. win1 > wins =. wins + 2 {. +/ i1{cts > echo 'new 1 wins at turn '; turns; wins > cts =. cts#~ -. win1 > pscr =. pscr#~-. win1 > 'pos1 scr1 pos2 scr2' =. |: ~. pscr > end. > NB. player 2 > turns =. >: turns > pos2 =. m10 , pos2 +/ die3 > cts =. ,cts <.@*/ ctdie3 > scr2 =. pos2 + ndie3 # scr2 > pscr =. (pos2,. scr2),.~ ndie3#pos1,. scr1 > cts =. pscr +//. cts > 'pos1 scr1 pos2 scr2' =. |: pscr =. ~. pscr > if. +/ win2=. tgt <: scr2 do. > i2 =. I. win2 > wins =. wins + _2 {. +/ i2{cts > echo 'new 2 wins at turn '; turns; wins > cts =. cts#~ -. win2 > pscr =. pscr#~-. win2 > 'pos1 scr1 pos2 scr2' =. |: ~. pscr > end. > end. > turns; wins > ) > > Cheers, > > Mike > > On 11/01/2022 00:17, Raul Miller wrote: > > Your 10&|&.<: is probably more comprehensible than my 11 |&.<: > > > > But for part B, how did you handle the smearing of scores that > > resulted from those new positions and counts? > > > > Thanks, > > > > > -- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
