blob: 871ad0bd1e581bda0ca567481488b63b7b908360 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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";
|