]> www.fi.muni.cz Git - aoc.git/blob - 2017/17.pl
Day 25: examining the input
[aoc.git] / 2017 / 17.pl
1 #!/usr/bin/perl
2
3 use v5.30;
4 use strict;
5
6 chomp (my $stream = <>);
7
8 1 while $stream =~ s/<[^!>]*!./</;
9 1 while $stream =~ s/<[^>]*?>//;
10
11 my $sum;
12 my $depth = 0;
13 for my $c (split //, $stream) {
14         if ($c eq '{') {
15                 $depth++;
16         } elsif ($c eq '}') {
17                 $sum += $depth--;
18         }
19 }
20
21 say $sum;