diff options
| author | 冯昶 <seaker@qq.com> | 2020-10-10 18:34:15 +0800 |
|---|---|---|
| committer | 冯昶 <seaker@qq.com> | 2020-10-10 18:34:15 +0800 |
| commit | f0a88ea2365d8ae7dfb90c969d83368a18b53f9a (patch) | |
| tree | 64665b115f1023519b48f3f366bb743ab68375d8 /challenge-079 | |
| parent | 353a66fe9f75298e44b27d692109259646e7d09f (diff) | |
| parent | a8ea1576ec8f1801e4c90d906c5d3c18ebde5ca6 (diff) | |
| download | perlweeklychallenge-club-f0a88ea2365d8ae7dfb90c969d83368a18b53f9a.tar.gz perlweeklychallenge-club-f0a88ea2365d8ae7dfb90c969d83368a18b53f9a.tar.bz2 perlweeklychallenge-club-f0a88ea2365d8ae7dfb90c969d83368a18b53f9a.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-079')
| -rw-r--r-- | challenge-079/bob-lied/perl/lib/CountSetBit.pm | 14 | ||||
| -rwxr-xr-x | challenge-079/james-smith/perl/ch-1.pl | 5 |
2 files changed, 9 insertions, 10 deletions
diff --git a/challenge-079/bob-lied/perl/lib/CountSetBit.pm b/challenge-079/bob-lied/perl/lib/CountSetBit.pm index 1733d4e676..068be81e2a 100644 --- a/challenge-079/bob-lied/perl/lib/CountSetBit.pm +++ b/challenge-079/bob-lied/perl/lib/CountSetBit.pm @@ -1,3 +1,4 @@ +## Please see file perltidy.ERR # vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: #============================================================================= # CountSetBit.pm @@ -17,18 +18,17 @@ use feature qw/ signatures /; no warnings qw/ experimental::signatures /; require Exporter; -our @ISA = qw(Exporter); -our @EXPORT = qw(); +our @ISA = qw(Exporter); +our @EXPORT = qw(); our @EXPORT_OK = qw(); -sub new($class, $n) +sub new ( $class, $n ) { $class = ref($class) || $class; my $self = { _n => $n, - _sum => 0, - }; + _sum => 0, }; bless $self, $class; return $self; } @@ -40,14 +40,14 @@ sub run($self) return ( $self->{_sum} % 1000000007 ); } -sub _bitsOf($self, $n)a +sub _bitsOf ( $self, $n ) { my $count = 0; while ( $n > 0 ) { $count++; - $n = $n & ($n-1); + $n = $n & ( $n - 1 ); } return $count; } diff --git a/challenge-079/james-smith/perl/ch-1.pl b/challenge-079/james-smith/perl/ch-1.pl index 75a2e92922..5b5ad927f1 100755 --- a/challenge-079/james-smith/perl/ch-1.pl +++ b/challenge-079/james-smith/perl/ch-1.pl @@ -62,11 +62,10 @@ sub count_set_bits { my $t = my $s = 0; while (@q) { next unless shift @q; - $t += ($s + @q/2)*(1<<@q); - $t %= 1000000007; + $t += ($s + @q/2) * (1<<@q); $s++; } - return $t; + return $t % 1000000007; } sub naive_count_set_bits { |
