summaryrefslogtreecommitdiffstats
path: root/2020/day2/pwcountcheck.pl
diff options
context:
space:
mode:
authorYigit Sever2021-12-12 01:24:32 +0300
committerYigit Sever2021-12-12 01:24:32 +0300
commit4bb6f8d06c0e384f3394012b1d48da58ed28cc5e (patch)
treed6478c85c0488a1059567ccd2882cb10039c2546 /2020/day2/pwcountcheck.pl
parentae3853b6e8ab02023ccd74baac6dc177b1ee879a (diff)
downloadaoc-4bb6f8d06c0e384f3394012b1d48da58ed28cc5e.tar.gz
aoc-4bb6f8d06c0e384f3394012b1d48da58ed28cc5e.tar.bz2
aoc-4bb6f8d06c0e384f3394012b1d48da58ed28cc5e.zip
2020, tracking
Diffstat (limited to '2020/day2/pwcountcheck.pl')
-rw-r--r--2020/day2/pwcountcheck.pl22
1 files changed, 22 insertions, 0 deletions
diff --git a/2020/day2/pwcountcheck.pl b/2020/day2/pwcountcheck.pl
new file mode 100644
index 0000000..636a5d0
--- /dev/null
+++ b/2020/day2/pwcountcheck.pl
@@ -0,0 +1,22 @@
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/(?'first'\d+)-(?'second'\d+) (?'char'\w): (?'rest'\w+)/) {
11
12 my $first = $+{first};
13 my $second = $+{second};
14
15 # https://www.effectiveperlprogramming.com/2010/12/count-the-number-of-things-in-a-string/
16 my $count = () = $+{rest} =~ /$+{char}/g;
17
18 $valid++ if $count >= $first and $count <= $second;
19 }
20}
21
22print("$valid");