From bc20ee1a81457cd08d82f4cd35d71b9c5f0f27f6 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Tue, 7 Dec 2021 09:59:09 -0500 Subject: Solve day 7 part 1 --- 2021/day07.pl | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 2021/day07.pl diff --git a/2021/day07.pl b/2021/day07.pl new file mode 100644 index 0000000..209bcb2 --- /dev/null +++ b/2021/day07.pl @@ -0,0 +1,7 @@ +use strict; +use warnings; +my @crabs = sort { $a <=> $b } split(/,/, <>); +my $median = $crabs[@crabs / 2]; +my $cost = 0; +$cost += abs($_ - $median) for @crabs; +print "$cost\n"; -- cgit 1.4.1