]> www.fi.muni.cz Git - aoc.git/blobdiff - 2021/13.pl
Moved 2021 to a subdir
[aoc.git] / 2021 / 13.pl
diff --git a/2021/13.pl b/2021/13.pl
new file mode 100755 (executable)
index 0000000..79740a3
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/bin/perl -w
+
+use v5.16;
+
+my @c = split /[,\s]/, <>;
+
+my $max;
+($max = !$max || $max < $_ ? $_ : $max) for @c;
+
+my $min_f;
+for my $pos (0 .. $max) {
+       my $f = 0;
+       $f += abs($_ - $pos) for @c;
+       $min_f = $f if !$min_f || $min_f > $f;
+       # say "$pos $f $min_f";
+}
+
+say $min_f;