Well, this is the part I know isn't working right

if ( $dr4 < 0 ) { #pre-populate deletion array; my @delarray = ( 0 .. $chntot + 1 ); @dlarray = shuffle @delarray; my $cndiea = 0; foreach my $del ( 0 .. $chntot ) { if ( $aod[$del][$yb] eq 'd' ) { $cndiea++; } } my $cnr = 0; my $cnx = $cndiea; while ( $cnx < $incrsdel ) { foreach my $xd ( 0 .. $chntot) { my $xda = $dlarray[$xd]; if ( $aod[$xda][$yb] eq 'a' ) { $aod[$xda][$yb] = 'd'; $cnr++; } } $cnx = $cnr; }

What this is supposed to do is, on an array with 'a's, 'd's, and 'n's, is count the 'd's, compare that number to what it's supposed to be, then randomly choose an 'a' to turn into a 'd' until the numbers match. Instead, it turns all the 'a's into 'd's. I actually have better luck with :

if ( $dr4 < 0 ) { #pre-populate deletion array; my @delarray = ( 0 .. $chntot + 1 ); @dlarray = shuffle @delarray; my $cndiea = 0; foreach my $del ( 0 .. $chntot ) { if ( $aod[$del][$yb] eq 'd' ) { $cndiea++; } } my $cnr = $cndiea; foreach my $xd ( $cnr .. $incrsdel - 1 ) { my $xda = $dlarray[$xd]; if ( $aod[$xda][$yb] eq 'a' ) { $aod[$xda][$yb] = 'd'; } } }

This version only fails about 5% of the time, depending on the ratio of 'd's to 'a's.

What am I not seeing?


In reply to Re: This runs WAY too slow by Dandello
in thread This runs WAY too slow by Dandello

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.