Skip to content

Commit

Permalink
The polished version of the limited-to-a-64-bit-word version.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredor committed May 9, 2020
1 parent 8c07c3e commit 177df50
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions challenge-059/jaredor/perl/ch-2.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@

# 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;

0 comments on commit 177df50

Please sign in to comment.