Question 6: A Perl solution
sub solve {
local($_) = @_;
s{\A\s+}{};
s{\s+\z}{};
my $cell_ref = '\b[A-Z][0-9]{1,3}\b';
if(m{\A($cell_ref)\s*[+]\s*($cell_ref)\z}) {
return cell_value($1) + cell_value($2);
}
elsif(m{\A($cell_ref)\s*[-]\s*($cell_ref)\z}) {
return cell_value($1) - cell_value($2);
}
elsif(m{\A($cell_ref)\s*[*]\s*($cell_ref)\z}) {
return cell_value($1) * cell_value($2);
}
elsif(m{\A($cell_ref)\s*[/]\s*($cell_ref)\z}) {
return cell_value($1) / cell_value($2);
}
elsif(m{\ASQRT\(($cell_ref)\)\z}) {
return sqrt(cell_value($1));
}
elsif(m{\AMAX\((.*?)\)\z}) {
my $ref_list = $1;
my $max = 0;
foreach my $ref ( $ref_list =~ m{($cell_ref)}g) {
my $val = cell_value($ref);
$max = $val if $val > $max;
}
return $max;
}
elsif(m{\A(\S.*?)\s*[+]\s*($cell_ref)\z}) {
my $val2 = cell_value($2);
return solve($1) + $val2;
}
else {
die "Don't know how to solve: '$_'\n";
}
}