diff options
author | Yigit Sever | 2021-12-13 10:38:11 +0300 |
---|---|---|
committer | Yigit Sever | 2021-12-13 10:38:11 +0300 |
commit | 74b27ccca31bb757c737dd7fdc02f513f57561b2 (patch) | |
tree | e27db4cd0873c81a53d32277446d926d176304e0 /2020/day2/pwcountcheck.pl | |
parent | 3919f90cfbfbba26c8e39f979280649f5e08aea8 (diff) | |
parent | ac8125750abed263619da4cc6d653bb5ab76f007 (diff) | |
download | aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.tar.gz aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.tar.bz2 aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.zip |
Merge remote-tracking branch 'origin/main'
Diffstat (limited to '2020/day2/pwcountcheck.pl')
-rw-r--r-- | 2020/day2/pwcountcheck.pl | 22 |
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 @@ | |||
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/(?'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 | |||
22 | print("$valid"); | ||