#!perl
use strict;
use warnings;
no warnings 'uninitialized';
use Algorithm::Loops 'MapCarU';
my @cols =
MapCarU {
join '',
map {
/\S/
? $_
: "\0"
}
@_
}
map { [ split // ] }
<>;
my ( $best_col, $best_sum );
for my $starting_col ( 10 .. $#cols - 10) {
my $sum = 0;
for my $col ( 0 .. 9 ) {
my $bits =
unpack 'b*',
$cols[$col] & $cols[ $starting_col + $col ];
$sum += $+[0] - $-[0] while $bits =~ /11*/g;
}
if ( not( defined $best_col ) or $best_sum < $sum ) {
$best_col = $starting_col;
$best_sum = $sum;
}
}
print "$best_col\n";
|