Thanks, that's helpful, although the tacit version of "bulk" is a bit too much for me to parse.
I imagine factor of 2 helps because it gets you over the expected 6r5 rolls per "game", assuming I did that recurrence right (e=(5r6*1)+1r6*(1+e)). I do have some lingering style questions though: 1. It looks to me like David Lambert's solution used both (&>) and (">) to force a verb to apply to the atoms, which I would write ("0). Are there any particular reasons to prefer one over the other? ("0) may require a ([) to avoid merging with a follow-up literal, (&>) seems a little like exploiting a side-effect of (>), and (">) could just as easily be ("+) or any other 0 0 0 verb. 2. Is there any difference between (bind) and (@:)? They look to me like they would be identical. Thanks, Johann On Thu, Sep 25, 2014 at 3:10 PM, Raul Miller <rauldmil...@gmail.com> wrote: > That is very close to what I came up with, for the case where we want only > a single value from our result: > > d6=:1 + ? bind 6 > repd6=: [:+/(,d6)^:(6={:)@d6 > > Here's a variation on Roger Hui's approach, for the case where we want N > values from our result: > > d6s=: 1 + [: ? #&6 > bulk=:{.#&0(],~(+/;.1~1:}:@,0~:6&|)@(],d6s@[))^:(0=6&|@{:@{.)^:_~] > > Example use: > bulk 20 > 5 5 5 4 3 3 2 3 3 9 1 4 16 3 3 1 3 17 3 4 > > This would probably be much clearer if implemented explicitly rather than > tacitly, and probably would be more efficient also. So: > > bulkd6s=:3 :0 > r=. i. 0 > while. y >: #r do. > r=. r, d6s y > mask=. }: 1, 0~:6|r > r=. mask +/;.1 r > end. > y{.r > ) > > But statistically speaking, this is still not as efficient as it could be. > I think we'd do better with: > > bulkd6=:3 :0 > r=. i. 0 > while. y >: #r do. > r=. r, d6s 2*y > mask=. }: 1, 0~:6|r > r=. mask +/;.1 r > end. > y{.r > ) > > Do you see why this tends to be more efficient? > > Thanks, > > -- > Raul > > > On Thu, Sep 25, 2014 at 11:50 AM, 'Pascal Jasmin' via Programming < > programm...@jsoftware.com> wrote: > >> this works >> >> (, >:@?@6:)^:((0=#) +. 6={:)^:_ i.0 >> >> ([: +/ (, >:@?@6:)^:((0=#) +. 6={:)^:_) i.0 >> 11 >> >> >> >> ----- Original Message ----- >> From: Johann Hibschman <jhibsch...@gmail.com> >> To: Programming forum <programm...@jsoftware.com> >> Cc: >> Sent: Thursday, September 25, 2014 9:06 AM >> Subject: [Jprogramming] Repeated rolling dice >> >> Hi all, >> >> For fun, I've been running some statistics for a game with an unusual >> rule for rolling dice: if a 6 is rolled, roll again and add the >> result, repeating on any subsequent 6s. I wanted to implement this in >> J, collecting all the individual rolls (rather than just the sum.) >> >> It seems like there should be a more clever and elegant way to do >> this, but this is what I have: >> >> NB. Simple roll. >> roll0 =: >:@? >> >> NB. This seems to work, but it's not very clever. >> roll =: 3 : 0 >> r =. >:?y >> if. r=y do. r=. r,(roll y) end. >> r >> ) >> >> NB. Attempt at iterating via power. Fails because repeats >> NB. signal termination. >> roll0^:(6&=)^:(<_) 6 >> >> NB. Attempt at iterating via agenda. Not even close yet. >> NB. ]`(]+$:) @. (=&6) NB. where to stick in the roll? >> >> This gives what I expect: >> >> roll"0 ] 10#6 >> 6 1 0 >> 3 0 0 >> 3 0 0 >> 2 0 0 >> 5 0 0 >> 2 0 0 >> 6 6 2 >> 2 0 0 >> 1 0 0 >> 6 3 0 >> >> But is there a better way to do this? Also, are there any known issues >> with the RNG? I've not gathered enough statistics to prove it, but the >> results look clumpier (more identical values in a row) than I expect. >> Now, I know that's a common cognitive bias, so it may just be me, but >> is there a discussion of the quality of the RNG somewhere? >> >> Thanks, >> Johann >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm