diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-04-03 00:45:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-03 00:45:18 +0100 |
| commit | 0f91f6099716ca6ed37f82697cfdcd9f4807a36b (patch) | |
| tree | 5581fdbef75339426321ec8ed0b8818b6a036157 | |
| parent | 191db50cc99221f9e244c6199329d7f3ae504b60 (diff) | |
| parent | faf0518fdd1805ab468bf26d5017975202110e8c (diff) | |
| download | perlweeklychallenge-club-0f91f6099716ca6ed37f82697cfdcd9f4807a36b.tar.gz perlweeklychallenge-club-0f91f6099716ca6ed37f82697cfdcd9f4807a36b.tar.bz2 perlweeklychallenge-club-0f91f6099716ca6ed37f82697cfdcd9f4807a36b.zip | |
Merge pull request #7825 from oldtechaa/avery-adams
Add solutions by Avery Adams
| -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; |
