summary refs log tree commit diff homepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-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";
lds by tab onlyJune McEnroe 2021-01-12List both Makefile and html.sh under README.7June McEnroe 2021-01-12Add htagml exampleJune McEnroe 2021-01-12Use mandoc and htagml for bin htmlJune McEnroe 2021-01-12Add htagmlJune McEnroe 2021-01-12Replace causal.agency with a simple mdoc pageJune McEnroe 2021-01-11Publish "Using vi"June McEnroe 2021-01-11Enable diff.colorMovedJune McEnroe 2021-01-10Set less search case-insensitiveJune McEnroe 2021-01-10Set EXINITJune McEnroe 2021-01-09Add c -t flag to print expression typeJune McEnroe 2021-01-05Update taglineJune McEnroe