about summary refs log tree commit diff
path: root/day08.pl
diff options
context:
space:
mode:
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)