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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |