about summary refs log tree commit diff
path: root/day08.pl
blob: 3a5e8a0d4a1f043f8e5a539ac1f9cce7622e6d3b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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)