aboutsummaryrefslogtreecommitdiff
path: root/challenge-263/ash/perl
diff options
context:
space:
mode:
authorAndrew Shitov <mail@andreyshitov.com>2024-04-02 08:55:26 +0200
committerAndrew Shitov <mail@andreyshitov.com>2024-04-02 08:55:26 +0200
commit6ccd059d128a87bfcc67d42046bb4cf67a1a40af (patch)
tree5d096ca2871aa5184f08a38108eae3202c144f95 /challenge-263/ash/perl
parenta4a5c909234335cbf64764b067d3d0f23829f8fc (diff)
downloadperlweeklychallenge-club-6ccd059d128a87bfcc67d42046bb4cf67a1a40af.tar.gz
perlweeklychallenge-club-6ccd059d128a87bfcc67d42046bb4cf67a1a40af.tar.bz2
perlweeklychallenge-club-6ccd059d128a87bfcc67d42046bb4cf67a1a40af.zip
Task 2 by ash
Diffstat (limited to 'challenge-263/ash/perl')
-rw-r--r--challenge-263/ash/perl/ch-2.pl31
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-263/ash/perl/ch-2.pl b/challenge-263/ash/perl/ch-2.pl
new file mode 100644
index 0000000000..82804b51e6
--- /dev/null
+++ b/challenge-263/ash/perl/ch-2.pl
@@ -0,0 +1,31 @@
+# Solution to Task 2 of The Weekly Challenge 263
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-263/#TASK2
+
+# $ perl ch-2.pl
+# $VAR1 = [
+# [
+# 1,
+# 4
+# ],
+# [
+# 2,
+# 3
+# ],
+# [
+# 3,
+# 2
+# ]
+# ];
+
+use v5.20;
+use Data::Dumper;
+
+my $items1 = [[1, 1], [2, 1], [3, 2]];
+my $items2 = [[2, 2], [1, 3]];
+
+my %values;
+$values{$_->[0]} += $_->[1] for @$items1, @$items2;
+
+my @result = map {[$_ + 0, $values{$_}]} sort {$a <=> $b} keys %values;
+
+say Dumper(\@result);