aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-09-26 11:56:47 +0100
committerGitHub <noreply@github.com>2020-09-26 11:56:47 +0100
commit4738d62fba07a0fbc3b52fa5682873451f679d38 (patch)
tree1b0626a74f04e21791a6e5f3d0c06b426b6b1d51
parent1ac0b05188e44ca889ace85bf0e8974d83feb7b6 (diff)
parente5043e278b4081462aee2f9b636c436ceaa75817 (diff)
downloadperlweeklychallenge-club-4738d62fba07a0fbc3b52fa5682873451f679d38.tar.gz
perlweeklychallenge-club-4738d62fba07a0fbc3b52fa5682873451f679d38.tar.bz2
perlweeklychallenge-club-4738d62fba07a0fbc3b52fa5682873451f679d38.zip
Merge pull request #2377 from manfredi/challenge-079
Perl solution for task #1
-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";