The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

#!/usr/bin/perl
use strict;
use constant MAX => 100_000;
my $max = int($ARGV[0] || MAX);
my $progress = Term::ProgressBar->new({
name => 'Powers',
count => $max,
remove => 3,
});
$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 == $_;
}
$next_update = $progress->update($_)
if $_ > $next_update;
}
$progress->update($max)
if $max >= $next_update;