I think this looks good.  However, please do not rename toss to toss1 and
toss2. Users can do that for themselves.  I want to end with a concise set
of statements everyone can use and we'll all get the same results.

I'm hoping you or someone can make the noun for toss.

Nice work.

Linda

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

Responses inline.

2011/12/1 Linda Alvord <lindaalv...@verizon.net>:
> Dice has a little problem that was caused by the difficulty in
transmitting
> the result without the code that creates it.  I would appreciate it if you
> would correct and reply to this message so the dice look like this (sort
> of). The two and the three should be on a diagonal from upper left to
lower
> right:
>
> ----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---+---+---+---+---+----
>

I see now will do.

>
> Please add the following lines to your script and then it will be easy for
> the reader to see that it has complied with the rules. Assert is a
wonderful
> addition for this and future challenges!
>
>   dice
>   toss
>   toss
>   fd c
>   0 0 0 3 = 4!:0 ;:'dice toss c fd'
>
> Also, you couldn't follow my rules and I couldn't either! I wanted a
niladic
> function (no arguments) which is what you wrote. But it always returns the
> same result. A monadic function would be better in the long run, but it
> would be nice also if someone could follow the original instructions. I
> could write it so
> Toss 6 gave the new tosses each time.

Hmmm... My reading of the original rules was that toss should be a
noun. As a noun it will be fixed. If you want it to be a verb (here
are no niladic verbs in J) then ( 4!:0 <'toss' ) should result in a 3
not a 0.

Here is an updated version. Not quite sure if it is what you were after
though:

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=: <"2 facechars {~ facerows {~ faces   NB. create dice
throw=: ] {~ [: ? [ $ [: # ]                NB. verb to throw dice
toss=: 2 10 throw ]                         NB. throw 2 dice 10 times
sumThrows=: ([: +/ [: , 'o' = ,)&>/         NB. sum each throw
fd=: [: /:~ ({. , #)/.~                     NB. calc frequency distribution


   dice
+---+---+---+---+---+---+
|   |o  |o  |o o|o o|o o|
| o |   | o |   | o |o o|
|   |  o|  o|o o|o o|o o|
+---+---+---+---+---+---+
   ]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|  o|  o|  o|   |
+---+---+---+---+---+---+---+---+---+---+
   ]Toss2=: 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 |   |
|  o|   |o o|  o|o o|o o|  o|o o|   |  o|
+---+---+---+---+---+---+---+---+---+---+
   ]c=: sumThrows Toss2
8 4 9 4 7 10 7 9 7 7
   fd c
 4 2
 7 4
 8 1
 9 2
10 1
   assert 0 3 0 3 = 4!:0 'dice';'toss';'c';'fd'
----------------------------------------------------------------------
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