diff options
author | June McEnroe <june@causal.agency> | 2021-12-07 09:59:09 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2021-12-07 09:59:09 -0500 |
commit | bc20ee1a81457cd08d82f4cd35d71b9c5f0f27f6 (patch) | |
tree | 2562556462b4c8f6b933eed264d29a78402e02fc | |
parent | Use postfix for more (diff) | |
download | aoc-bc20ee1a81457cd08d82f4cd35d71b9c5f0f27f6.tar.gz aoc-bc20ee1a81457cd08d82f4cd35d71b9c5f0f27f6.zip |
Solve day 7 part 1
-rw-r--r-- | 2021/day07.pl | 7 |
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"; |