You might enjoy one of the responses I got from Henry Rich in 2012. It was a question about dice. I remember I had no idea what the last line meant and never managed to go back an figure it out until I looked at it again today and I understood it.
NB. Answer to a dice challenge from Henry Rich toss =: (dice =: (6 6 6#:12 145 157 185 197 215)<@:{"1 2 (#:i.6){' o'){~ 2 10 ?@$ 6: a=:6 3$0 2 0 4 0 1 4 2 1 5 0 5 5 2 5 5 5 5 6 6 6#.a 12 145 157 185 197 215 g=:' o' b=:#:i.6 d=:b{g dice=:<"2 a{"1 2 d dice ----T---T---T---T---T---┐ │ │o │o │o o│o o│o o│ │ o │ │ o │ │ o │o o│ │ │ o│ o│o o│o o│o o│ L---+---+---+---+---+---- s=:[:?(2 10$6)"_ c=:s'' s [: ? (2 10$6)"_ c 2 5 1 3 3 3 4 5 1 0 5 0 5 0 3 0 1 3 5 1 dice{~c=:s'' ----T---T---T---T---T---T---T---T---T---┐ │o │o o│o o│o o│o o│o o│o o│ │ │o │ │ │ │o o│o o│ │ │ │ o │ o │ o │ │ o│o o│o o│o o│o o│o o│o o│ │ │ o│ +---+---+---+---+---+---+---+---+---+---+ │o o│o o│o o│o o│o o│o o│o o│o │o │ │ │ o │ o │o o│ │o o│ o │ │ o │ o │ o │ │o o│o o│o o│o o│o o│o o│o o│ o│ o│ │ L---+---+---+---+---+---+---+---+---+---- 1+c 2 4 6 6 4 4 4 1 1 3 5 5 6 4 6 5 4 3 3 1 dice{~c=:s'' ----T---T---T---T---T---T---T---T---T---┐ │o │o o│o │o │o │ │o o│ │o o│o o│ │ │ o │ │ │ o │ o │ o │ o │o o│ o │ │ o│o o│ o│ o│ o│ │o o│ │o o│o o│ +---+---+---+---+---+---+---+---+---+---+ │o o│o o│ │ │ │o │o o│o │ │ │ │o o│ │ o │ o │ o │ │ o │ o │ o │ o │ │o o│o o│ │ │ │ o│o o│ o│ │ │ L---+---+---+---+---+---+---+---+---+---- 1+c 2 5 2 2 3 1 5 1 6 5 6 4 1 1 1 2 5 3 1 1 toss2=: 13 :'dice{~y' toss2 s'' ----T---T---T---T---T---T---T---T---T---┐ │o │o o│o │o │o o│o │o o│o o│o o│o o│ │ o │ o │ o │ o │ o │ o │o o│ o │ o │ o │ │ o│o o│ o│ o│o o│ o│o o│o o│o o│o o│ +---+---+---+---+---+---+---+---+---+---+ │o │o o│o o│o o│o │o o│o o│o o│o o│o o│ │ │ │ o │ o │ │o o│ o │ │ o │ │ │ o│o o│o o│o o│ o│o o│o o│o o│o o│o o│ L---+---+---+---+---+---+---+---+---+---- 1+c 2 5 2 2 3 1 5 1 6 5 6 4 1 1 1 2 5 3 1 1 toss2 s'' ----T---T---T---T---T---T---T---T---T---┐ │o │o o│o o│o │ │o o│ │ │o │o │ │ o │ o │ o │ o │ o │o o│ o │ o │ o │ o │ │ o│o o│o o│ o│ │o o│ │ │ o│ o│ +---+---+---+---+---+---+---+---+---+---+ │o o│o o│o │o │o o│o o│ │o │ │o │ │ │ │ o │ o │ │o o│ o │ o │ o │ │ │o o│o o│ o│ o│o o│o o│ │ o│ │ o│ L---+---+---+---+---+---+---+---+---+---- 1+c 2 5 2 2 3 1 5 1 6 5 6 4 1 1 1 2 5 3 1 1 5!:2 ;:'toss a g b d dice c toss2' --------------------------T-----T-----------------T---T---T---┐ │----T---T---T---T---T---┐│--T-┐│-----T-------T--┐│ │ │ │ ││ │o │o │o o│o o│o o│││{│~│││2 10│--T-T-┐│6:││ │ │ │ ││ o │ │ o │ │ o │o o││L-+--││ ││?│@│$││ ││ │ │ │ ││ │ o│ o│o o│o o│o o││ ││ │L-+-+--│ ││ │ │ │ │L---+---+---+---+---+----│ │L----+-------+---│ │ │ │ +-------------------------+-----+-----------------+---+---+---+ │0 2 0 │ │ │ │ │ │ │4 0 1 │ │ │ │ │ │ │4 2 1 │ │ │ │ │ │ │5 0 5 │ │ │ │ │ │ │5 2 5 │ │ │ │ │ │ │5 5 5 │ │ │ │ │ │ +-------------------------+-----+-----------------+---+---+---+ │ o │ │ │ │ │ │ +-------------------------+-----+-----------------+---+---+---+ │0 0 0 │ │ │ │ │ │ │0 0 1 │ │ │ │ │ │ │0 1 0 │ │ │ │ │ │ │0 1 1 │ │ │ │ │ │ │1 0 0 │ │ │ │ │ │ │1 0 1 │ │ │ │ │ │ +-------------------------+-----+-----------------+---+---+---+ │ │ │ │ │ │ │ │ o │ │ │ │ │ │ │ o │ │ │ │ │ │ │ oo │ │ │ │ │ │ │o │ │ │ │ │ │ │o o │ │ │ │ │ │ +-------------------------+-----+-----------------+---+---+---+ │ │o │o │o o│o o│o o│ │ o │ │ o │ │ o │o o│ │ │ o │ o │o o│o o│o o│ +-------------------------+-----+-----------------+---+---+---+ │1 4 1 1 2 0 4 0 5 4 │ │ │ │ │ │ │5 3 0 0 0 1 4 2 0 0 │ │ │ │ │ │ +-------------------------+-----+-----------------+---+---+---+ │----T---T---T---T---T---┐│--T-┐│] │ │ │ │ ││ │o │o │o o│o o│o o│││{│~││ │ │ │ │ ││ o │ │ o │ │ o │o o││L-+--│ │ │ │ │ ││ │ o│ o│o o│o o│o o││ │ │ │ │ │ │L---+---+---+---+---+----│ │ │ │ │ │ L-------------------------+-----+-----------------+---+---+---- NB. Answer to a dice challenge from Henry Rich 2012 toss =: (dice =: (6 6 6#:12 145 157 185 197 215)<@:{"1 2 (#:i.6){' o'){~ 2 10 ?@$ 6: a=:6 3$0 2 0 4 0 1 4 2 1 5 0 5 5 2 5 5 5 5 6 6 6#.a g=:' o' b=:#:i.6 d=:b{g dice=:<"2 a{"1 2 d dice s=:[:?(2 10$6)"_ c=:s'' s c dice{~c=:s'' 1+c dice{~c=:s'' 1+c toss2=: 13 :'dice{~y' toss2 s'' 1+c toss2 s'' 1+c 5!:2 ;:'toss a g b d dice c toss2' NB. Answer to a dice challenge from Henry Rich 2012 Linda -----Original Message----- From: programming-boun...@forums.jsoftware.com [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Johann Hibschman Sent: Thursday, September 25, 2014 9:06 AM To: Programming forum 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