summary refs log tree commit diff homepage
path: root/2021
diff options
context:
space:
mode:
Diffstat (limited to '2021')
-rw-r--r--2021/day10.pl12
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";