aboutsummaryrefslogtreecommitdiff
path: root/challenge-079
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-09-27 14:18:34 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-09-27 14:18:34 +0100
commit9d61e22614c244db9074f1d6ff92c81eeeb9696e (patch)
treef4a1ca25c0ae36e359916317deef72019da6fe31 /challenge-079
parentc5de6f59b6d631a5c12f04968793d0cd28311c69 (diff)
downloadperlweeklychallenge-club-9d61e22614c244db9074f1d6ff92c81eeeb9696e.tar.gz
perlweeklychallenge-club-9d61e22614c244db9074f1d6ff92c81eeeb9696e.tar.bz2
perlweeklychallenge-club-9d61e22614c244db9074f1d6ff92c81eeeb9696e.zip
- Added solutions by Simon Green.
Diffstat (limited to 'challenge-079')
-rwxr-xr-xchallenge-079/sgreen/perl/ch-1.pl28
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-079/sgreen/perl/ch-1.pl b/challenge-079/sgreen/perl/ch-1.pl
new file mode 100755
index 0000000000..ed0628ca60
--- /dev/null
+++ b/challenge-079/sgreen/perl/ch-1.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+sub main {
+ my $N = shift;
+ my $count = 0;
+
+ # Sanity check
+ die "Please enter a positive integer\n" unless $N;
+ die "The value '$N' is not a positive integer\n"
+ unless $N =~ /^[1-9][0-9]*$/;
+
+ my $b = 1;
+ while ( $b < $N ) {
+ foreach my $i ( 1 .. $N ) {
+ $count++ if $i & $b;
+ }
+ $b *= 2;
+ }
+
+ printf qq(%d %% %d = %d\n), $count, 1000000007, $count % 1000000007;
+}
+
+main(@ARGV);
+