summaryrefslogtreecommitdiffstats
path: root/2020/day2/pwindexcheck.pl
diff options
context:
space:
mode:
authorYigit Sever2021-12-13 10:38:11 +0300
committerYigit Sever2021-12-13 10:38:11 +0300
commit74b27ccca31bb757c737dd7fdc02f513f57561b2 (patch)
treee27db4cd0873c81a53d32277446d926d176304e0 /2020/day2/pwindexcheck.pl
parent3919f90cfbfbba26c8e39f979280649f5e08aea8 (diff)
parentac8125750abed263619da4cc6d653bb5ab76f007 (diff)
downloadaoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.tar.gz
aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.tar.bz2
aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.zip
Merge remote-tracking branch 'origin/main'
Diffstat (limited to '2020/day2/pwindexcheck.pl')
-rw-r--r--2020/day2/pwindexcheck.pl19
1 files changed, 19 insertions, 0 deletions
diff --git a/2020/day2/pwindexcheck.pl b/2020/day2/pwindexcheck.pl
new file mode 100644
index 0000000..69a26b5
--- /dev/null
+++ b/2020/day2/pwindexcheck.pl
@@ -0,0 +1,19 @@
1use strict;
2use warnings;
3
4open my $fh, '<', "input" or die "no input present, $!";
5
6my $valid = 0;
7
8while (my $line = <$fh>) {
9 chomp $line;
10 if ($line =~ m/(?<idx_1>\d+)-(?<idx_2>\d+) (?<char>\w): (?<rest>\w+)/) {
11
12 my $first = substr( $+{rest}, $+{idx_1} - 1 , 1 );
13 my $second = substr( $+{rest}, $+{idx_2} - 1 , 1 );
14
15 $valid++ if $first eq $+{char} xor $second eq $+{char};
16 }
17}
18
19print("$valid");