diff options
author | June McEnroe <june@causal.agency> | 2021-12-10 11:46:57 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2021-12-10 11:46:57 -0500 |
commit | 48d7c62520ea05f6ad23a00d37f9e5b90bd4542e (patch) | |
tree | b8fa887058237104c1fde574176ef65d9aff322a | |
parent | Solve day 10 part 1 (diff) | |
download | aoc-48d7c62520ea05f6ad23a00d37f9e5b90bd4542e.tar.gz aoc-48d7c62520ea05f6ad23a00d37f9e5b90bd4542e.zip |
Solve day 10 part 2
Diffstat (limited to '')
-rw-r--r-- | 2021/day10.pl | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/2021/day10.pl b/2021/day10.pl index 871ad0b..e35db27 100644 --- a/2021/day10.pl +++ b/2021/day10.pl @@ -2,8 +2,8 @@ use strict; use warnings; my %pairs = ('(', ')', '[', ']', '{', '}', '<', '>'); my %scores = (')' => 3, ']' => 57, '}' => 1197, '>' => 25137); -my $score; -while (<>) { +my ($score, @scores2); +LINE: while (<>) { chomp; my @stack; for (split //) { @@ -13,8 +13,14 @@ while (<>) { shift @stack; } else { $score += $scores{$_}; - last; + next LINE; } } + next unless @stack; + my $score2 = 0; + $score2 = $score2 * 5 + 1 + index(')]}>', $_) for @stack; + push @scores2, $score2; } print "$score\n"; +@scores2 = sort { $a <=> $b } @scores2; +print $scores2[@scores2 / 2], "\n"; |