summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-12-10 11:46:57 -0500
committerJune McEnroe <june@causal.agency>2021-12-10 11:46:57 -0500
commit115a65575c049f41c650a256c96ca30f3d5aaf17 (patch)
tree8a54d25c48c49acc0c24847bda559fc110b2affe
parentSolve day 10 part 1 (diff)
downloadaoc-115a65575c049f41c650a256c96ca30f3d5aaf17.tar.gz
aoc-115a65575c049f41c650a256c96ca30f3d5aaf17.zip
Solve day 10 part 2
-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";
37e8d09bc&follow=1'>Add PS0June McEnroe 2019-01-13Change default ENV from cashrc to env.shJune McEnroe 2019-01-13Use colours in cash promptsJune McEnroe 2019-01-12Set PSlit like NetBSD shJune McEnroe 2019-01-12Install gnupg2 from pkgsrc and symlink gpgJune McEnroe 2019-01-12Reference cash builtin man pages in cash.1 SEE ALSOJune McEnroe 2019-01-12Restore cash builtin man page datesJune McEnroe 2019-01-12Use local libeditJune McEnroe 2019-01-12Replace libedit MakefileJune McEnroe 2019-01-11Import /usr/src/lib/libedit from NetBSD 8.0June McEnroe 2019-01-11Add PSlit for prompt escapesJune McEnroe 2019-01-11Don't make depend automaticallyJune McEnroe