File: powers4

package info (click to toggle)
libterm-progressbar-perl 2.23-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 224 kB
  • sloc: perl: 596; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 540 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/perl
use strict;
use warnings;

use Term::ProgressBar 2.00;

use constant MAX => 1_000_000;

my $max = int($ARGV[0] || MAX);
my $progress = Term::ProgressBar->new({
	name => 'Powers',
	count => $max,
	ETA => 'linear',
});
#$progress->minor(0);
my $next_update = 0;

for (0..$max) {
  my $is_power = 0;
  for(my $i = 0; 2**$i <= $_; $i++) {
    $is_power = 1
      if 2**$i == $_;
  }
sleep 1
if $_ % 4 == 0;

  $next_update = $progress->update($_)
    if $_ > $next_update;
}
$progress->update($max)
    if $max >= $next_update;