summaryrefslogtreecommitdiffstats
path: root/2020/day2/pwindexcheck.pl
blob: 69a26b5bd6d1e551c1054fb7d8c4928c8d72c8a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use strict;
use warnings;

open my $fh, '<', "input" or die "no input present, $!";

my $valid = 0;

while (my $line = <$fh>) {
    chomp $line;
    if ($line =~ m/(?<idx_1>\d+)-(?<idx_2>\d+) (?<char>\w): (?<rest>\w+)/) {

        my $first = substr( $+{rest}, $+{idx_1} - 1 , 1 );
        my $second = substr( $+{rest}, $+{idx_2} - 1 , 1 );

        $valid++ if $first eq $+{char} xor $second eq $+{char};
    }
}

print("$valid");