aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-079/manfredi/perl/ch-1.pl18
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-079/manfredi/perl/ch-1.pl b/challenge-079/manfredi/perl/ch-1.pl
new file mode 100755
index 0000000000..3b1c77a9a1
--- /dev/null
+++ b/challenge-079/manfredi/perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+my $N = $ARGV[0] || 5;
+my $one = 0;
+
+print "Input: \$N = $N\n";
+
+for my $n (1..$N) {
+ $_ = sprintf("%b", $n);
+ my $bit = tr/1//d;
+ printf "\tDecimal: %d\n\tBinary: 0b%08b\n\tSet Bit Count: %d\n\n", $n, $n, $bit;
+ $one += $bit;
+}
+
+my $z = $one % 1000000007;
+print "Total set bit count: ($one % 1000000007) = $z\n";