summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--2021/day07.pl7
1 files changed, 7 insertions, 0 deletions
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";