diff options
author | Yigit Sever | 2021-12-12 01:24:32 +0300 |
---|---|---|
committer | Yigit Sever | 2021-12-12 01:24:32 +0300 |
commit | 4bb6f8d06c0e384f3394012b1d48da58ed28cc5e (patch) | |
tree | d6478c85c0488a1059567ccd2882cb10039c2546 /2020/day2/pwindexcheck.pl | |
parent | ae3853b6e8ab02023ccd74baac6dc177b1ee879a (diff) | |
download | aoc-4bb6f8d06c0e384f3394012b1d48da58ed28cc5e.tar.gz aoc-4bb6f8d06c0e384f3394012b1d48da58ed28cc5e.tar.bz2 aoc-4bb6f8d06c0e384f3394012b1d48da58ed28cc5e.zip |
2020, tracking
Diffstat (limited to '2020/day2/pwindexcheck.pl')
-rw-r--r-- | 2020/day2/pwindexcheck.pl | 19 |
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 @@ | |||
1 | use strict; | ||
2 | use warnings; | ||
3 | |||
4 | open my $fh, '<', "input" or die "no input present, $!"; | ||
5 | |||
6 | my $valid = 0; | ||
7 | |||
8 | while (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 | |||
19 | print("$valid"); | ||