#!/usr/bin/env perl
use strict;
use warnings;


# Read it all in
open (my $fh, '<', 'input') or die "$!";
my $i = 0;
my @M = ();
for my $l (<$fh>) {
    chomp $l;
    $M[$i] = [split('', $l)];
    $i++;
}

# Do work on the matrix
my @slopes = (
    [1,1],
    [3,1],
    [5,1],
    [7,1],
    [1,2],
);

my @N;
for (my $k = 0; $k < scalar @slopes; $k++) {
    my ($r, $d) = @{$slopes[$k]};
    my $j = 0;
    for (my $i = 0; $i < scalar @M; $i += $d) {
        if ($M[$i]->[$j] eq '#') {
            $N[$k]++;
        }
        $j = ($j + $r) % scalar @{$M[0]};
    }
}

print join(",", @N) . "\n";
my $total = 1;
$total *= $_ for @N;
print "$total\n";
