there's a small issue with it, (if last roll is a 6)
(}:1,6~:x) <;.1 x=. 6 1 6 6 2 3 6
┌───┬─────┬─┬─┐
│6 1│6 6 2│3│6│
└───┴─────┴─┴─┘
if you've never seen a use for i.15 0 before,
([: +/ (, >:@?@6:)^:((0=#) +. 6={:)^:_)"1 i.15 0
3 13 3 3 11 1 2 3 5 4 9 4 1 3 1
or
(, >:@?@6:)^:((0=#) +. 6={:)^:_"1 i.15 0
1 0 0
2 0 0
6 2 0
5 0 0
5 0 0
1 0 0
5 0 0
1 0 0
2 0 0
2 0 0
4 0 0
6 6 5
6 2 0
6 1 0
2 0 0
----- Original Message -----
From: Devon McCormick <[email protected]>
To: J-programming forum <[email protected]>
Cc:
Sent: Thursday, September 25, 2014 1:40 PM
Subject: Re: [Jprogramming] Repeated rolling dice
This looks like a good addition to my growing set of "array-thinking"
examples.
On Thu, Sep 25, 2014 at 12:32 PM, Roger Hui <[email protected]>
wrote:
> Compared to the other solutions posted so far, I believe it is more
> straightforward to do a long sequence of dice rolls and then split it up
> according to your specified criteria. The split point are where the
> _previous_ roll is _not_ a 6. Thus:
>
> x=: 1+1e4 ?@$ 6 NB. long sequence of dice rolls
> x
> 5 4 6 1 5 4 5 6 1 3 5 1 2 3 3 6 5 2 4 5 6 5 5 3 6 2 4 4 1 3 6 4 2 1 5 6 1 6
> 6 6 6 6 5 4 6 1 2 3 2 5 1 2 1 3 2 ...
> (}:1,6~:x) <;.1 x
>
> ┌─┬─┬───┬─┬─┬─┬───┬─┬─┬─┬─┬─┬─┬───┬─┬─┬─┬───┬─┬─┬───┬─┬─┬─┬─┬───┬─┬─┬─┬───┬───────────┬─┬───┬─┬─┬─┬─┬─┬─┬─┬─┬─┬
> │5│4│6 1│5│4│5│6 1│3│5│1│2│3│3│6 5│2│4│5│6 5│5│3│6 2│4│4│1│3│6 4│2│1│5│6
> 1│6 6 6 6 6 5│4│6 1│2│3│2│5│1│2│1│3│2│ ...
>
> └─┴─┴───┴─┴─┴─┴───┴─┴─┴─┴─┴─┴─┴───┴─┴─┴─┴───┴─┴─┴───┴─┴─┴─┴─┴───┴─┴─┴─┴───┴───────────┴─┴───┴─┴─┴─┴─┴─┴─┴─┴─┴─┴
>
>
>
>
> On Thu, Sep 25, 2014 at 6:06 AM, Johann Hibschman <[email protected]>
> wrote:
>
> > 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
>
--
Devon McCormick, CFA
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm