about summary refs log tree commit diff
path: root/day08.pl
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2019-12-09 20:49:26 +0100
committerLeah Neukirchen <leah@vuxu.org>2019-12-09 20:49:26 +0100
commit69d73187d5fb12de0923fef08013c9c8a2f4298a (patch)
tree15b8cf64ecf502ad85544870883e13942c872e17 /day08.pl
parent62ddf8eb1da577429cc08d18ccfc7ca30eead73e (diff)
downloadadventofcode2019-69d73187d5fb12de0923fef08013c9c8a2f4298a.tar.gz
adventofcode2019-69d73187d5fb12de0923fef08013c9c8a2f4298a.tar.xz
adventofcode2019-69d73187d5fb12de0923fef08013c9c8a2f4298a.zip
day08
Diffstat (limited to 'day08.pl')
-rw-r--r--day08.pl22
1 files changed, 22 insertions, 0 deletions
diff --git a/day08.pl b/day08.pl
new file mode 100644
index 0000000..3a5e8a0
--- /dev/null
+++ b/day08.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/perl -w
+use v5.16;
+
+use File::Slurper 'read_lines';
+use List::Util qw'reduce';
+
+my @d = unpack "(A150)*", (read_lines('day08'))[0];
+
+my $p1 = reduce { (()=$a =~ /0/g) > (()=$b =~ /0/g) ? $b : $a } @d;
+say((()=$p1 =~ /1/g)*(()=$p1 =~ /2/g));
+
+my $p2 = "";
+INDEX: for my $i (0..149) {
+    for (@d) {
+        if ((my $c = substr($_, $i, 1)) ne "2") {
+            $p2 .= $c;
+            next INDEX;
+        }
+    }
+} 
+$p2 =~ tr/01/ #/;
+say join "\n", unpack("(A25)*", $p2)