]> www.fi.muni.cz Git - aoc2021.git/blob - 20.pl
Day 25: pretty straightforward
[aoc2021.git] / 20.pl
1 #!/usr/bin/perl -w
2
3 use v5.16;
4
5 my %score_of = (
6         '(' => 1,
7         '[' => 2,
8         '{' => 3,
9         '<' => 4,
10 );
11
12 my @sums;
13 while (<>) {
14         chomp;
15         my $sum = 0;
16         1 while s/\(\)|\[\]|\{\}|\<\>//;
17         next if /[\)\]\}\>]/;
18         next if !length;
19         for my $c (reverse split //) {
20                 $sum *= 5;
21                 $sum += $score_of{$c};
22         }
23         push @sums, $sum;
24 }
25
26 @sums = sort { $a <=> $b } @sums;
27 say $sums[@sums/2];
28