This is a rearranged version of Henry Rich's beautiful one line version. His
development is especially important if you are teaching probability. The use
of the binary system is worth pondering:

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
cc=:[:?2 10$6:
c=:cc''
c
c=:cc''
c
dice{~c=:cc''
1+c
dice{~c=:cc''
1+c
toss2=: 13 :'dice{~y'
toss2 cc''
1+c
toss2 cc''
1+c
5!:2 ;:'toss a g b d dice cc c toss2'

I was able to do everything required of my challenge except one thing. Just
as Henry did not define a final function for toss and capture the values in
the actual toss, I could not either. Unfortunately that is vital to the
central idea of this exercise.
Maybe someone will figure it out.

This strategy seems to me to belong a little later in a course in J than the
Turkey Roll Challenge. However it leads right in nicely to counting, bases
and combinations and was too good to ignore.

Linda

-----Original Message-----
From: programming-boun...@jsoftware.com
[mailto:programming-boun...@jsoftware.com] On Behalf Of Linda Alvord
Sent: Sunday, December 04, 2011 4:32 AM
To: 'Programming forum'
Subject: Re: [Jprogramming] Turkey Roll - Challenge 2

Me too.

toss =: (dice =: (6 6 6#:12 145 157 185 197 215)<@:{"1 2 (#:i.6){' o'){~ 2
10 ?@$ 6:
a=:' o'
b=:#:i.6 
d=:b{a
e=:6 6 6#:12 145 157 185 197 215
dice=: e<@:{"1 2 d
dice
f=:2 10?@ $ 6:
c=: 13 :'(2 10?@$6:){dice'
c''
toss =:dice{~f
c''
toss''
c''
toss''
c''
5!:2 ;:'a b d e dice f c toss'

I can't get the toss to work

Linda

-----Original Message-----
From: programming-boun...@jsoftware.com
[mailto:programming-boun...@jsoftware.com] On Behalf Of Ric Sherlock
Sent: Sunday, December 04, 2011 4:09 AM
To: Programming forum
Subject: Re: [Jprogramming] Turkey Roll - Challenge 2

NB. Inspired by Henry's dice:

facechars=: ' o'
facerows=: #: i.6
faces=: 6 #.inv 12 145 157 185 197 215
dice=: <"2 facechars {~ facerows {~ faces   NB. create dice
dvals=: 1 + i. # dice

NB. Sort of what you've asked for:

throw=: ] {~ [: ? [ $ [: # ]                NB. verb to throw dice
throw210=: 2 10 throw ]                     NB. throw 2 dice 10 times
displayDi=: dice {~ <:                      NB. show dice
toss=: [: displayDi throw210                NB. throw 2 dice 10 times

   dvals
1 2 3 4 5 6
   throw210 dvals
2 3 6 4 5 3 5 5 1 5
5 3 3 5 5 3 2 4 3 4
   displayDi throw210 dvals  NB. display as toss as dice
   toss dvals                NB. equivalent as single verb
   toss dvals

I don't really like hiding the assignment of a global noun inside the
verb toss but if I had to do it:

tossc=: 3 : 'displayDi c =: throw210 y'

On Sun, Dec 4, 2011 at 4:40 AM, Linda Alvord <lindaalv...@verizon.net>
wrote:
> I'm comparing tosses, so could you match this in your own style:
>
> sla=: 13 :'cla=:1+? 2 10$y'
> tossla=: 13 :'(<"2)3 3$"1(<:sla y){d'
> tossla 6
> cla
> tossla 6
> cla
>
> My  c  is a noun of the actual "dice" that are tossed.  The display should
> no longer be necessary for everyone to know what is happening.
>
> Toss will then require the number of faces on the die.  This will ultimate
> be the result of a toss.
>
> throwrs=: ] {~ [: ? [ $ [: # ]
> tossrs=: 2 10 throw dice
>
> Thanks in advance.  I'm enjoying your style.
>
> Linda
>
> -----Original Message-----
> From: programming-boun...@jsoftware.com
> [mailto:programming-boun...@jsoftware.com] On Behalf Of Ric Sherlock
> Sent: Thursday, December 01, 2011 6:01 AM
> To: Programming forum
> Subject: Re: [Jprogramming] Turkey Roll - Challenge 2
>
> The following is getting away from the actual rules as of the task but
> is perhaps useful nonetheless ...
>
> From a storage and processing POV, it will be leaner and faster not to
> store the dice boxed. The boxing is nice for display purposes though
> so that could be made a separate verb.
>
> facerows=: 0 0 0,1 0 0,0 1 0,0 0 1,:1 0 1   NB. row types on faces
> facechars=: ' o'                            NB. chars used to draw faces
> faces=: 0 2 0,1 0 3,1 2 3,4 0 4,4 2 4,:4 4 4  NB. define faces as rows
> dice=: facechars {~ facerows {~ faces       NB. create dice
> displayDice=: [: smoutput <"2               NB. display boxed di
> throw=: ] {~ [: ? [ $ [: # ]                NB. verb to throw dice
> toss=: 2 10 throw ]                         NB. throw 2 dice 10 times
> sumThrows=: [: +/ [: ([: +/ ,)"2 'o' = ]    NB. sum each throw
> fd=: [: /:~ ({. , #)/.~                     NB. calc frequency
distribution
>
>   displayDice dice
> +---+---+---+---+---+---+
> |   |o  |o  |o o|o o|o o|
> | o |   | o |   | o |o o|
> |   |  o|  o|o o|o o|o o|
> +---+---+---+---+---+---+
>   displayDice Toss1=: toss dice
> +---+---+---+---+---+---+---+---+---+---+
> |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|
> +---+---+---+---+---+---+---+---+---+---+
>   sumThrows Toss1
> 5 4 9 4 5 5 5 6 10 7
> ----------------------------------------------------------------------
> 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

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to