From 48d7c62520ea05f6ad23a00d37f9e5b90bd4542e Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 10 Dec 2021 11:46:57 -0500 Subject: Solve day 10 part 2 --- 2021/day10.pl | 12 +++++++++--- 1 file 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"; -- cgit 1.4.1