use strict; my @x; open(FIL,"prob81data.txt"); while () { my $l = $_; chomp($l); my @p = split(',',$l); push @x, \@p; } close(FIL); my $s = 79; for (my $i = $s; $i >= 0; $i--) { #i is the width for (my $j = $s; $j >= 0; $j--) { #j is the height if ($j < $s) { if ($i < $s) { #anywhere in the middle if ($x[$i + 1][$j] < $x[$i][$j + 1]) { $x[$i][$j] = $x[$i][$j] + $x[$i + 1][$j]; } else { $x[$i][$j] = $x[$i][$j] + $x[$i][$j + 1]; } } else { #bottom row, to the left $x[$i][$j] = $x[$i][$j] + $x[$i][$j + 1]; } } elsif ($i < $s) { #rightmost row $x[$i][$j] = $x[$i][$j] + $x[$i + 1][$j]; } } } print ($x[0][0] . "\n");