aboutsummaryrefslogtreecommitdiff
path: root/challenge-059
diff options
context:
space:
mode:
authorJared Martin <jaredor+github@gmail.com>2020-05-09 16:57:34 -0500
committerJared Martin <jaredor+github@gmail.com>2020-05-09 16:57:34 -0500
commit177df50b7a6f4702e666b5e7377a8ffe4eef61f1 (patch)
tree191cde433223a1b688825e5f04e0a76b5aec19ee /challenge-059
parent8c07c3e93f48b59e6d8aa89414274b1d1cdc6d88 (diff)
downloadperlweeklychallenge-club-177df50b7a6f4702e666b5e7377a8ffe4eef61f1.tar.gz
perlweeklychallenge-club-177df50b7a6f4702e666b5e7377a8ffe4eef61f1.tar.bz2
perlweeklychallenge-club-177df50b7a6f4702e666b5e7377a8ffe4eef61f1.zip
The polished version of the limited-to-a-64-bit-word version.
Diffstat (limited to 'challenge-059')
-rwxr-xr-xchallenge-059/jaredor/perl/ch-2.pl14
1 files changed, 7 insertions, 7 deletions
diff --git a/challenge-059/jaredor/perl/ch-2.pl b/challenge-059/jaredor/perl/ch-2.pl
index 9acee3e679..ce5ae1f0cd 100755
--- a/challenge-059/jaredor/perl/ch-2.pl
+++ b/challenge-059/jaredor/perl/ch-2.pl
@@ -9,21 +9,21 @@ use List::Util qw(all sum);
# Answer based on perl doc for unpack and www.perlmonks.org/?node_id=407933
-my ( $LL, $NN ) =
- defined $Config{longlongsize}
- ? ( 8 * $Config{longlongsize}, 'Q' )
- : ( 8 * $Config{longsize}, 'N' );
-
die "This script requires one or more positive integer arguments."
unless @ARGV;
die "Not all arguments to the script are positive integers."
unless all { /\A [1-9] \d* \Z/xms } @ARGV;
+my ( $LL, $NN ) =
+ defined $Config{longlongsize}
+ ? ( 8 * $Config{longlongsize}, 'Q' )
+ : ( 8 * $Config{longsize}, 'L' );
+
my @nums = map { pack "${NN}*", $_ } @ARGV;
-my (@diffbits, $num);
-while ($num = shift @nums) {
+my ( @diffbits, $num );
+while ( $num = pop @nums ) {
push @diffbits, unpack( "%${LL}b*", $num ^ $_ ) for @nums;
}
say @diffbits ? sum @diffbits : 0;