]> www.fi.muni.cz Git - aoc.git/blobdiff - 2020/4.pl
Moved 2020 to a subdir
[aoc.git] / 2020 / 4.pl
diff --git a/2020/4.pl b/2020/4.pl
new file mode 100755 (executable)
index 0000000..d16915a
--- /dev/null
+++ b/2020/4.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+my $count = 0;
+
+while (<>) {
+       my ($min, $max, $letter, $pass) = /\A(\d+)-(\d+)\s+(\S):\s+(\S+)\s*\z/;
+       if (!defined $pass) {
+               print "Divny radek $_\n";
+               next;
+       }
+
+       no warnings 'substr';
+       # no warnings 'uninitialized';
+       $count++ if !!(substr($pass, $min-1, 1) eq $letter)
+               + !!(substr($pass, $max-1, 1) eq $letter)
+               == 1;
+}
+
+print $count, "\n";
+