OK thanks, I understand now. I was reading 20 50-digit numbers rather than 1 1000-digit numbers. I knew it a fundamental misunderstanding somewhere. Thank you again,
Derrick ------------------------------------------------------------------发件人:Shlomi Fish<shlo...@shlomifish.org>日 期:2017年05月16日 16:54:39收件人:<derr...@thecopes.me>抄 送:Beginners Perl List<beginners@perl.org>主 题:Re: project euler #8Hi all! Resending because the original message does not appear to have arrived at the list. ===== Hi Derrick, On Tue, 16 May 2017 14:01:34 +0800 derr...@thecopes.me wrote: > Hi All, > > I am working on problem #8 of the euler project. see below. > > > I have the below solution below for this which works fine but gives me the > wrong answer. I checked shlomifish's solution on github and his is similar to > mine, more elegant since he uses "map", but he gets a different answer. I > feel like I have some basic misunderstanding about how something should work. > Or maybe I am misunderstanding the problem. Thanks in advance for any push in > the right direction. see my solution below. > > Derrick > > #! /usr/bin/env perl > > use strict; > use warnings; > use 5.024; > use List::Util qw(max product); > > my $totalmax = 0; > > while ( my $numbline = <DATA> ) { > chomp $numbline; > my @numbline = split //, $numbline; You're processing the input number line-by-line, but it's one whole number and the products may span across more than one line. You need to slurp it and prepare an array of digits. > say "@numbline "; > my @product = (); > for (0..$#numbline - 13) { This should be "@numbline - 13" - an off-by-one error. Regards, Shlomi Fish