From 0fd901be032e4c877b1a4a15bc8721548952dbc3 Mon Sep 17 00:00:00 2001 From: southpawgeek Date: Sun, 8 Mar 2020 18:28:01 -0400 Subject: update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 42398c3620..663ddd08fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea .precomp/ +.DS_Store -- cgit From 7f394ed37d30ba0057d66fc682fbd7f03a050346 Mon Sep 17 00:00:00 2001 From: southpawgeek Date: Sun, 12 Apr 2020 01:43:48 -0400 Subject: ignore vstags --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 663ddd08fc..0d74b6c749 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea .precomp/ .DS_Store +.vstags -- cgit From 38b9a5ef023b76b9729e608a21583f88eba9246a Mon Sep 17 00:00:00 2001 From: southpawgeek Date: Sun, 12 Apr 2020 01:43:56 -0400 Subject: challenge 1 --- challenge-055/southpawgeek/perl/ch-1.pl | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 challenge-055/southpawgeek/perl/ch-1.pl 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 -- cgit