diff options
| -rw-r--r-- | challenge-210/avery-adams/perl/ch-1.pl | 15 | ||||
| -rw-r--r-- | challenge-210/avery-adams/perl/ch-2.pl | 33 |
2 files changed, 48 insertions, 0 deletions
diff --git a/challenge-210/avery-adams/perl/ch-1.pl b/challenge-210/avery-adams/perl/ch-1.pl new file mode 100644 index 0000000000..6a63b82bac --- /dev/null +++ b/challenge-210/avery-adams/perl/ch-1.pl @@ -0,0 +1,15 @@ +#!/usr/bin/perl + +use strict; +use v5.10; + +my %hash; +$hash{$_}++ for @ARGV; + +my $max; +for my $int (keys %hash) { + my $total = (($int - 1) * $hash{$int - 1}) + ($int * $hash{$int}) + (($int + 1) * $hash{$int + 1}); + $max = $total if $total > $max or !defined($max); +} + +say $max if defined $max; diff --git a/challenge-210/avery-adams/perl/ch-2.pl b/challenge-210/avery-adams/perl/ch-2.pl new file mode 100644 index 0000000000..2610085fb3 --- /dev/null +++ b/challenge-210/avery-adams/perl/ch-2.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +use strict; +use v5.10; + +my @list = @ARGV; +for (my $index = 0; $index < $#list; $index++) { + my $collision = $list[$index] + $list[$index + 1]; + if ($collision > $list[$index]) {next} + elsif ($collision > 0) { + splice @list, $index + 1, 1; + $index--; + } elsif ($collision == 0) { + splice @list, $index, 2; + $index -= 2; + } elsif (0 > $collision > $list[$index + 1]) { + splice @list, $index, 1; + for (my $index2 = $index - 1; $index2 >= 0 and $list[$index2] > 0; $index2--) { + if (-$list[$index] > $list[$index2]) { + splice @list, $index2, 1; + $index--; + $index2--; + } elsif (-$list[$index] == $list[$index2]) { + splice @list, $index2, 2; + $index -= 2; + } else { + splice @list, $index, 1; + $index--; + } + } + } +} +say $_ for @list; |
