#!/usr/bin/perl -w

use strict;

my $field = do { local $/; <> };
my $rows = $field =~ s/\s//g;
my $flen = length $field;
my $cols = $flen/$rows;

print "Field has $flen bytes, in $rows rows and $cols cols\n";

sub slope {
	my ($colstep, $rowstep) = @_;

	$colstep += $cols;

	my $col = 0;
	my $sum = 0;
	my $row = 0;
	while ($row < $rows) {
		print "row $row\n";
		$sum++ if substr($field, $row*$cols + $col, 1) eq '#';
		$col += $colstep;
		$col %= $cols;
		$row += $rowstep;
	}
	print "$colstep x $rowstep, sum=$sum\n";
	return $sum;
}

print "Total: ",
	slope(1, 1)
	* slope(3, 1)
	* slope(5, 1)
	* slope(7, 1)
	* slope(1, 2),
	"\n";

