#!/usr/bin/perl use strict; # How much do you bet per turn? my $bet = 10; # How many turns before you give up? my $max_iterations = 2000; # At what point shall you stop due to success? my $stop_win = 100; # At what point must you stop due to losses? my $max_loss = -500; my $iterations = 0; my $balance = 0; my $lowest = 0; my $done = 0; do { $iterations++; my $rand = rand() * (36/37); if ($rand > 0.5) { $balance = $balance + $bet; } else { $balance = $balance - $bet; } if ($balance >= $stop_win) { $done = 1; print "WINNAR!\n"; } if ($balance <= $lowest) { $lowest = $balance; } if ($iterations >= $max_iterations) { $done = 1; print "GIVE UP!\n"; } if ($balance <= $max_loss) { $done = 1; print "YUO LOSE!\n"; } # If you've reached half your turns and got 1/2 your target money, stop early if ($iterations >= ($max_iterations / 2) and $balance >= ($stop_win / 4)) { $done = 1; print "GOOD ENOUGH!\n"; } # further addition -- if you nearly broke the bank but crawled back up to zero if ($lowest <= ($max_loss * 0.75) and $balance >= 0 ) { $done = 1; print "WHEW!\n"; } #print "$iterations, $balance \n"; #print "$balance\n"; } while ($done == 0); print "iterations: $iterations\nlowest: $lowest\nbalance: $balance\n";