aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Manfredi <manfredi@cpan.org>2020-09-26 12:07:42 +0200
committerLeo Manfredi <manfredi@cpan.org>2020-09-26 12:07:42 +0200
commite5043e278b4081462aee2f9b636c436ceaa75817 (patch)
tree1b0626a74f04e21791a6e5f3d0c06b426b6b1d51
parent1ac0b05188e44ca889ace85bf0e8974d83feb7b6 (diff)
downloadperlweeklychallenge-club-e5043e278b4081462aee2f9b636c436ceaa75817.tar.gz
perlweeklychallenge-club-e5043e278b4081462aee2f9b636c436ceaa75817.tar.bz2
perlweeklychallenge-club-e5043e278b4081462aee2f9b636c436ceaa75817.zip
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";