diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-04-12 08:49:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-12 08:49:02 +0100 |
| commit | 1cd05461b50b75048cfa87c64b0ea3c3c9c1988b (patch) | |
| tree | d80626925cec8efdb0a629456972c046c69fde44 | |
| parent | a3303cf1600e57dbdaa4259f549ba0dac637702a (diff) | |
| parent | 38b9a5ef023b76b9729e608a21583f88eba9246a (diff) | |
| download | perlweeklychallenge-club-1cd05461b50b75048cfa87c64b0ea3c3c9c1988b.tar.gz perlweeklychallenge-club-1cd05461b50b75048cfa87c64b0ea3c3c9c1988b.tar.bz2 perlweeklychallenge-club-1cd05461b50b75048cfa87c64b0ea3c3c9c1988b.zip | |
Merge pull request #1550 from southpawgeek/master
challenge 55 task 1
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | challenge-055/southpawgeek/perl/ch-1.pl | 45 |
2 files changed, 47 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index 42398c3620..0d74b6c749 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .idea .precomp/ +.DS_Store +.vstags diff --git a/challenge-055/southpawgeek/perl/ch-1.pl b/challenge-055/southpawgeek/perl/ch-1.pl new file mode 100644 index 0000000000..a4fb700785 --- /dev/null +++ b/challenge-055/southpawgeek/perl/ch-1.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl +use strict; +use warnings; +use feature qw/say/; + +my $B = "010"; +my @LR =( + {'L' => 0, 'R' => 0}, + {'L' => 0, 'R' => 1}, + {'L' => 0, 'R' => 2}, + {'L' => 1, 'R' => 1}, + {'L' => 1, 'R' => 2}, + {'L' => 2, 'R' => 2}); + +flip($B, $_) foreach @LR; + +my $pos; +my @max1s; + +sub flip { + my ($B, $LR) = @_; + my @N = unpack '(A)*', $B; + my $L = $LR->{'L'}; + my $R = $LR->{'R'}; + + say "L=$L, R=$R"; + + for ($L..$R) { + $N[$L] = 1 - $N[$L]; + $L++; + } + + say "$B -> ", @N; + say "-"x15; + + my $x = ("@N" =~ tr/1/1/); + push @{$max1s[$x]}, $LR; + $pos = $x if $x > $pos; +} + +say "max total positive bits: $pos"; +say "sets resulting in $pos positive bits"; + +my $max = pop @max1s; +say "L=", $_->{'L'}, " R=", $_->{'R'} foreach @$max;
\ No newline at end of file |
