]> git.donarmstrong.com Git - term-progressbar.git/blob - examples/powers5
bc0c310534c2feb00a63f8569fa3334c334790b8
[term-progressbar.git] / examples / powers5
1 #!/usr/bin/perl
2
3 use Term::ProgressBar 2.00;
4
5 use constant MAX => 10_000_000;
6
7 my $max = int($ARGV[0]+0) || MAX;
8 my $progress = Term::ProgressBar->new({name => 'Powers', count => $max,
9                                        ETA => linear, });
10 $progress->max_update_rate(1);
11 my $next_update = 0;
12
13 for (0..$max) {
14   my $is_power = 0;
15   for(my $i = 0; 2**$i <= $_; $i++) {
16     if ( 2**$i == $_ ) {
17       $is_power = 1;
18       $progress->message(sprintf "Found %8d to be 2 ** %2d", $_, $i);
19     }
20   }
21
22   $next_update = $progress->update($_)
23     if $_ > $next_update;
24 }
25 $progress->update($max)
26     if $max >= $next_update;