From d32d7daa368684f36ee8eb1c13c0c8c996ee5f8c Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 10 Dec 2021 11:36:45 -0500 Subject: Solve day 10 part 1 --- 2021/day10.pl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 2021/day10.pl (limited to '2021') diff --git a/2021/day10.pl b/2021/day10.pl new file mode 100644 index 0000000..871ad0b --- /dev/null +++ b/2021/day10.pl @@ -0,0 +1,20 @@ +use strict; +use warnings; +my %pairs = ('(', ')', '[', ']', '{', '}', '<', '>'); +my %scores = (')' => 3, ']' => 57, '}' => 1197, '>' => 25137); +my $score; +while (<>) { + chomp; + my @stack; + for (split //) { + if (index('([{<', $_) != -1) { + unshift @stack, $pairs{$_}; + } elsif ($_ eq $stack[0]) { + shift @stack; + } else { + $score += $scores{$_}; + last; + } + } +} +print "$score\n"; -- cgit 1.4.1