]> www.fi.muni.cz Git - aoc2020.git/blob - 4.pl
Task 9 Perl Golf-style
[aoc2020.git] / 4.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 my $count = 0;
6
7 while (<>) {
8         my ($min, $max, $letter, $pass) = /\A(\d+)-(\d+)\s+(\S):\s+(\S+)\s*\z/;
9         if (!defined $pass) {
10                 print "Divny radek $_\n";
11                 next;
12         }
13
14         no warnings 'substr';
15         # no warnings 'uninitialized';
16         $count++ if !!(substr($pass, $min-1, 1) eq $letter)
17                 + !!(substr($pass, $max-1, 1) eq $letter)
18                 == 1;
19 }
20
21 print $count, "\n";
22