<?xml version="1.0" encoding="windows-1252"?>
<node id="892772" title="Re^2: Monte Carlo - Coin Toss" created="2011-03-11 20:22:58" updated="2011-03-11 20:22:58">
<type id="11">
note</type>
<author id="540414">
jwkrahn</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;i&gt;
It is more idiomatic (and often simpler) to use Perl-style rather than C-style loops.
&lt;/i&gt;&lt;/blockquote&gt;
&lt;p&gt;
Yes, but it won't work if the numbers are too large for integers and have to use floating point. &amp;nbsp;&amp;nbsp; Then only C style loops will work.
&lt;/p&gt;



&lt;blockquote&gt;&lt;i&gt;&lt;c&gt;
my @collect = map 0, 0 .. NUM_TOSSES;
&lt;/c&gt;&lt;/i&gt;&lt;/blockquote&gt;
&lt;p&gt;
Why are you initializing &lt;c&gt;@collect&lt;/c&gt; with &lt;c&gt;NUM_TOSSES + 1&lt;/c&gt; elements?
&lt;/p&gt;
&lt;p&gt;
The idiomatic way to initialize &lt;c&gt;@collect&lt;/c&gt; with &lt;c&gt;NUM_TOSSES&lt;/c&gt; elements is usually:
&lt;/p&gt;
&lt;c&gt;
my @collect = ( 0 ) x NUM_TOSSES;
&lt;/c&gt;


&lt;blockquote&gt;&lt;i&gt;&lt;strike&gt;&lt;c&gt;
for ($i = 0; $i &lt; $numTosses+1; $i++) {

foreach my $tailsCt ( 0 .. NUM_TOSSES )
&lt;/c&gt;&lt;/i&gt;&lt;/blockquote&gt;
&lt;p&gt;
You have an off-by-one error, it should be:
&lt;/p&gt;
&lt;c&gt;
foreach my $tailsCt ( 0 .. NUM_TOSSES - 1 )
&lt;/c&gt;
&lt;p&gt;
&lt;/strike&gt;
&lt;b&gt;Update:&lt;/b&gt; oops, I misread the original code.
&lt;/p&gt;
</field>
<field name="root_node">
892293</field>
<field name="parent_node">
892669</field>
</data>
</node>
