package LargestSeriesProduct; use strict; use warnings; use List::Util qw( product ); use Exporter qw; our @EXPORT_OK = qw; sub largest_product { my ($input) = @_; die "digits input must only contain digits" if ($input->{digits} =~ m/\D+/); die "span must be greater than zero" if ($input->{span} < 0); my @digits = split //, $input->{digits}; my $length = scalar @digits; die "span must be smaller than string length" if ($input->{span} > $length); my $max = 0; foreach my $i (0 .. $length - $input->{span}) { my @substring = @digits[$i .. ($i + $input->{span} - 1)]; my $product = product @substring; $max = $product if ($product > $max); } return $max; } 1;