2016-18
This commit is contained in:
parent
b342b3783a
commit
6836f6e229
34
2016/18/1.pl
Normal file
34
2016/18/1.pl
Normal file
@ -0,0 +1,34 @@
|
||||
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;
|
1
2016/18/input.txt
Normal file
1
2016/18/input.txt
Normal file
@ -0,0 +1 @@
|
||||
^^.^..^.....^..^..^^...^^.^....^^^.^.^^....^.^^^...^^^^.^^^^.^..^^^^.^^.^.^.^.^.^^...^^..^^^..^.^^^^
|
Loading…
Reference in New Issue
Block a user