]> git.donarmstrong.com Git - term-progressbar.git/blob - examples/powers3
82ae2248fccd626f99f26f075098bee959d83a0c
[term-progressbar.git] / examples / powers3
1 #!/usr/bin/perl
2
3 use Term::ProgressBar 2.00;
4
5 use constant MAX => 100_000;
6
7 my $max = int($ARGV[0]+0) || MAX;
8 my $progress = Term::ProgressBar->new({name => 'Powers', count => $max, remove => 3});
9 $progress->minor(0);
10 my $next_update = 0;
11
12 for (0..$max) {
13   my $is_power = 0;
14   for(my $i = 0; 2**$i <= $_; $i++) {
15     $is_power = 1
16       if 2**$i == $_;
17   }
18
19   $next_update = $progress->update($_)
20     if $_ > $next_update;
21 }
22 $progress->update($max)
23     if $max >= $next_update;