Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
29
Task/Population-count/Perl/population-count-1.pl
Normal file
29
Task/Population-count/Perl/population-count-1.pl
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use feature 'say';
|
||||
|
||||
sub evil {
|
||||
my $i = 0;
|
||||
sub { $i++ while population_count($i) % 2; $i++ }
|
||||
}
|
||||
|
||||
sub odious {
|
||||
my $i = 0;
|
||||
sub { $i++ until population_count($i) % 2; $i++ }
|
||||
}
|
||||
|
||||
sub population_count {
|
||||
my $n = shift;
|
||||
my $c;
|
||||
for ($c = 0; $n; $n >>= 1) { $c += $n & 1 }
|
||||
$c
|
||||
}
|
||||
|
||||
say join ' ', map { population_count 3**$_ } 0 .. 30 - 1;
|
||||
|
||||
my (@evil, @odious);
|
||||
my ($evil, $odious) = (evil, odious);
|
||||
push( @evil, $evil->() ), push @odious, $odious->() for 1 .. 30;
|
||||
|
||||
say "Evil @evil";
|
||||
say "Odious @odious";
|
||||
1
Task/Population-count/Perl/population-count-2.pl
Normal file
1
Task/Population-count/Perl/population-count-2.pl
Normal file
|
|
@ -0,0 +1 @@
|
|||
say unpack("%b*",pack "J*", 1234567); # J = UV
|
||||
11
Task/Population-count/Perl/population-count-3.pl
Normal file
11
Task/Population-count/Perl/population-count-3.pl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
use ntheory qw/hammingweight/;
|
||||
say hammingweight(1234567);
|
||||
|
||||
use Math::GMPz qw/Rmpz_popcount/;
|
||||
say Rmpz_popcount(Math::GMPz->new(1234567));
|
||||
|
||||
use Math::BigInt;
|
||||
say 0 + (Math::BigInt->new(1234567)->as_bin() =~ tr/1//);
|
||||
|
||||
use Bit::Vector;
|
||||
say Bit::Vector->new_Dec(64,1234567)->Norm;
|
||||
Loading…
Add table
Add a link
Reference in a new issue