adventofcode/2016/18/1.pl

35 lines
701 B
Perl
Raw Normal View History

2018-02-27 17:53:22 +00:00
use 5.20.0;
use experimental qw/ postderef /;
my @levels = (
map { chomp; [
map { $_ eq '^' } split '' ] } <>
);
use DDP;
p @levels;
my $sum = 0;
use List::AllUtils qw/ sum /;
for ( 1..400000-1 ) {
my @previous = ( 0, $levels[-1]->@* );
my @new;
while( @previous >= 2 ) {
my( $left, $mid, $right ) = @previous;
push @new,
( $left && $mid && ! $right )
|| ( !$left && $mid && $right )
|| ( $left && !$mid && !$right )
|| ( !$left && !$mid && $right );
shift @previous;
}
push @levels, \@new;
$sum += sum map { !$_ } map { @$_ } shift @levels;
}
say sum $sum, map { !$_ } map { @$_ } @levels;