Below you will find my version with some changes. However, I've pointed out
some other versions that were superior to mine. When I tried to mix them I
got all mixed up. To do these two exercises, you may use any of the
statements below. Modify their use to:
1. Toss a pair of dice a million times and produce a frequency
distribution of the sums. This a simulation and there will be no graphic
images of the results.
2. Image a large bucket with 100 dice of each of the five Platonic
Solids. Each die is numbered from 1 with consecutive counting numbers.
Simulate the result and summarize your results in a frequency distribution
of the dice are all tosses from the bucket 200 times.
Here are the expression you may choose from along with J symbols. Make your
expressions as simple as possible. (I think Ric, Kip and Henry should just
watch and maybe referee if needed.)
d1=:' o '
d2=:'o o'
d3=:'o o o'
d4=:'o o o o'
d5=:'o o o o o'
d6=:'o oo oo o'
d=:6 9$d1,d2,d3,d4,d5,d6
dice=:(<"2)3 3$"1 d
dice
s=: 13 :'c=:1+?2 10$y'
toss=: 13 :'(<"2)3 3$"1(<:s y){d'
c
toss 6
c
toss=: 13 :'(<"2)3 3$"1(<:s y){d'
t=: 13 :'+/"2 y'
fd=: [: /:~ ~. ,. [: +/"1 =
dice
toss 6
c
t c
fd t c
toss 6
c
t c
fd t c
toss 4
c
t c
fd t c
assert 0 0 3 3 3 3 = 4!:0 ;:'dice c s t toss fd'
NB. dice is a graphic image of the faces of a die
NB. c captures the data from an array of random rolls of the dice
NB. s is the shape and s y allows for different dice
NB. t is a list of totals for each of the tosses
NB. fd is a frequency distribution of data in a list
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm