about summary refs log tree commit diff
path: root/day04.pl
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2019-12-06 15:58:53 +0100
committerLeah Neukirchen <leah@vuxu.org>2019-12-06 15:58:53 +0100
commite2fca96cdb4778318cae541e0ebfc3a76370422a (patch)
tree323fc098268ebaa9f22109833fa06c591ed5eb97 /day04.pl
parent0de529ff41514152fc8e8aaf49368a6e73bb2007 (diff)
downloadadventofcode2019-e2fca96cdb4778318cae541e0ebfc3a76370422a.tar.gz
adventofcode2019-e2fca96cdb4778318cae541e0ebfc3a76370422a.tar.xz
adventofcode2019-e2fca96cdb4778318cae541e0ebfc3a76370422a.zip
day04
Diffstat (limited to 'day04.pl')
-rw-r--r--day04.pl21
1 files changed, 21 insertions, 0 deletions
diff --git a/day04.pl b/day04.pl
new file mode 100644
index 0000000..f1137dc
--- /dev/null
+++ b/day04.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/perl -w
+use v5.16;
+
+my $d = "171309-643603";
+
+my ($a, $b) = split "-", $d;
+
+my $p1 = 0;
+my $p2 = 0;
+
+PASS: for ($a..$b) {
+    my @ds = split('');
+
+    if (join('',@ds) eq join('',sort(@ds))) {
+        $p1++ if /(\d)\1/;
+        while (/(\d)\1+/g) { $p2++, next PASS  if length($&) == 2; }
+    }
+}
+
+say $p1;  # 1625
+say $p2;  # 1111