summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-12-07 09:59:09 -0500
committerJune McEnroe <june@causal.agency>2021-12-07 09:59:09 -0500
commitbc20ee1a81457cd08d82f4cd35d71b9c5f0f27f6 (patch)
tree2562556462b4c8f6b933eed264d29a78402e02fc
parentUse postfix for more (diff)
downloadaoc-bc20ee1a81457cd08d82f4cd35d71b9c5f0f27f6.tar.gz
aoc-bc20ee1a81457cd08d82f4cd35d71b9c5f0f27f6.zip
Solve day 7 part 1
-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";