Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Monte Carlo - Coin Toss

by johngg (Abbot)
on Mar 12, 2011 at 12:38 UTC ( #892818=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Monte Carlo - Coin Toss
in thread Monte Carlo - Coin Toss

Why are you initializing @collect with NUM_TOSSES + 1 elements?

The idiomatic way to initialize @collect with NUM_TOSSES elements is usually:

my @collect = ( 0 ) x NUM_TOSSES;

As Eliya points out, 20 tosses could give 21 outcomes as regards the number of "tails" tossed, i.e. 0, 1, ... 19 or 20 so your way should be

my @collect = ( 0 ) x ( NUM_TOSSES + 1 );

and I would agree that your way is perhaps more idiomatic. However, I felt that

my @collect = map 0, 0 .. NUM_TOSSES;

better illustrated the relation between the numbers of tosses and outcomes. What do others think?

Cheers,

JohnGG


Comment on Re^3: Monte Carlo - Coin Toss
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://892818]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2015-07-04 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls