I'm trying to learn to work backwards from tacit to explicit. Here's what
happened.
This is a file that you can run.
s=:3 6 3 7 5 2 6 8 11 3
fdla=: 13 :'(~.(/:y){y),.+/"1 (~.(/:y){y)=/ y'
fdla
fdkm2=: 13 :'/:~(~.y),.+/"1 =y'
fdkm2
fdkm2=:[: /:~ ~. ,. [: +/"1 =
fdrs=: [: /:~ ({. , #)/.~
NB. x u/.y ↔ (=x) u@# y
NB. Nice function, but it has @
NB. Save for total J
NB. fd is now kip's version with one less nub
fdla=: ([: ~. /: { ]) ,. [: +/"1 ] =/~ [: ~. /: { ]
fdkm =: [: /:~ ~. ,. [: +/"1 ~. =/ ]
fdkm2=: [: /:~ ~. ,. [: +/"1 =
fdrs=: [: /:~ ({. , #)/.~
fd=: [: /:~ ~. ,. [: +/"1 =
fd is now kip's version with one less nub
Linda
-----Original Message-----
From: [email protected]
[mailto:[email protected]] 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 <[email protected]>:
> 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