]> www.fi.muni.cz Git - aoc2021.git/blob - 13.pl
Day 25: pretty straightforward
[aoc2021.git] / 13.pl
1 #!/usr/bin/perl -w
2
3 use v5.16;
4
5 my @c = split /[,\s]/, <>;
6
7 my $max;
8 ($max = !$max || $max < $_ ? $_ : $max) for @c;
9
10 my $min_f;
11 for my $pos (0 .. $max) {
12         my $f = 0;
13         $f += abs($_ - $pos) for @c;
14         $min_f = $f if !$min_f || $min_f > $f;
15         # say "$pos $f $min_f";
16 }
17
18 say $min_f;