in reply to Expecting a 100 solutions, getting just 1
It's hard to understand what you are trying to do. What is a "trial solution"? Is there some randomness involved?
If you want to store multiple somethings, you best use an array:
my @interesting_values; for (1...1000) { my $r = rand; if ($r > 0.5) { push @interesting_values, $r; } }
See also: perldata, perlintro.
This part of your code:
for ($i=0; $i<$i_max; $i++) { if ($z < $z_best) {
seems to be entirely useless, because you never set $z to anything, and there's no reason to iterate over that if-statement, since nothing in there is random or depends on $i.
Also please Use strict and warnings and declare your variables with my.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Expecting a 100 solutions, getting just 1
by doozy (Initiate) on Apr 17, 2012 at 08:58 UTC | |
by moritz (Cardinal) on Apr 17, 2012 at 09:10 UTC | |
by doozy (Initiate) on Apr 17, 2012 at 09:58 UTC |