From 177df50b7a6f4702e666b5e7377a8ffe4eef61f1 Mon Sep 17 00:00:00 2001 From: Jared Martin Date: Sat, 9 May 2020 16:57:34 -0500 Subject: The polished version of the limited-to-a-64-bit-word version. --- challenge-059/jaredor/perl/ch-2.pl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'challenge-059') 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; -- cgit