about summary refs log tree commit diff
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
parent0de529ff41514152fc8e8aaf49368a6e73bb2007 (diff)
downloadadventofcode2019-e2fca96cdb4778318cae541e0ebfc3a76370422a.tar.gz
adventofcode2019-e2fca96cdb4778318cae541e0ebfc3a76370422a.tar.xz
adventofcode2019-e2fca96cdb4778318cae541e0ebfc3a76370422a.zip
day04
-rw-r--r--day041
-rw-r--r--day04.k5
-rw-r--r--day04.pl21
3 files changed, 27 insertions, 0 deletions
diff --git a/day04 b/day04
new file mode 100644
index 0000000..2a9dae3
--- /dev/null
+++ b/day04
@@ -0,0 +1 @@
+171309-643603
diff --git a/day04.k b/day04.k
new file mode 100644
index 0000000..3902500
--- /dev/null
+++ b/day04.k
@@ -0,0 +1,5 @@
+#{|/1<#:'.=x}#p:{x~^x}#${x+!y-x}.`i$"-"\:"171309-643603"
+#{2 in #:'.=x}#p
+\\
+1625
+1111
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