aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-05-21 18:34:12 +0100
committerGitHub <noreply@github.com>2024-05-21 18:34:12 +0100
commit8d95ba54d50d1356232fe2b7c367857212866825 (patch)
treee7a60d3bee0ef8227b369e6f21608f2d04864003
parent222a3469ea716002549c6a1360c0ade0ea68b481 (diff)
parent87cdd09e5bf7913d961e0cc5b990e6a81c26ec9d (diff)
downloadperlweeklychallenge-club-8d95ba54d50d1356232fe2b7c367857212866825.tar.gz
perlweeklychallenge-club-8d95ba54d50d1356232fe2b7c367857212866825.tar.bz2
perlweeklychallenge-club-8d95ba54d50d1356232fe2b7c367857212866825.zip
Merge pull request #10133 from pme/challenge-270
challenge-270
-rwxr-xr-xchallenge-270/peter-meszaros/perl/ch-2.pl18
1 files changed, 15 insertions, 3 deletions
diff --git a/challenge-270/peter-meszaros/perl/ch-2.pl b/challenge-270/peter-meszaros/perl/ch-2.pl
index 3bf63a6f4d..ffa10fb245 100755
--- a/challenge-270/peter-meszaros/perl/ch-2.pl
+++ b/challenge-270/peter-meszaros/perl/ch-2.pl
@@ -69,11 +69,19 @@ use List::Util qw/max/;
my $cases = [
[[[4, 1], 3, 2], 9],
[[[2, 3, 3, 3, 5], 2, 1], 6],
+ [[[3, 3, 4, 4], 1, 1], 1],
+ [[[3, 3, 4, 4], 1, 2], 2],
+ [[[3, 3, 4, 4], 1, 3], 2],
];
# get max diff
-# for pair of maxes -> level2 --> decrement, count step and undef maxes
-# if exist single max -> level1 --> decrement, count step and undef maxes
+# for pair of maxes -> decrement
+# if level2 cheaper than two level1 --> count level2 step
+# else --> count two level1 step
+# undef maxes
+# if exist single max -> decrement
+# count level1 step
+# undef maxes
# repeat until max diff == 0
sub distribute_elements
{
@@ -95,7 +103,11 @@ sub distribute_elements
if (@max == 2) {
--$diff[$max[0]];
--$diff[$max[1]];
- ++$y_cnt;
+ if ((2 * $x) < $y) {
+ $x_cnt += 2;
+ } else {
+ ++$y_cnt;
+ }
undef @max;
}
}