## Posted By

cmm7825 on 05/20/10

# Problem 11

/ Published in: Perl

1. #!/usr/bin/perl
2. use strict;
3. use warnings;
4.
5. open INFILE, "<11.in";
6.
7. my (@a, @tmp, \$result);
8. my \$max = 0;
9.
10. while(<INFILE>){
11. @tmp = split;
12. push @a, [ @tmp ];
13. }
14.
15. for my \$r (0..\$#a){
16. for my \$c (0..\$#{\$a[\$r]}){
17. #up
18. if(\$r >= 3){
19. \$result = \$a[\$r][\$c]*\$a[\$r][\$c-1]*\$a[\$r][\$c-2]*\$a[\$r][\$c-3];
20. \$max = \$result if \$result > \$max;
21. }
22. #left
23. if(\$c >= 3){
24. \$result = \$a[\$r][\$c]*\$a[\$r-1][\$c]*\$a[\$r-2][\$c]*\$a[\$r-3][\$c];
25. \$max = \$result if \$result > \$max;
26. }
27. #back diagonal
28. if(\$c >= 3 && \$r >= 3){
29. \$result = \$a[\$r][\$c]*\$a[\$r-1][\$c-1]*\$a[\$r-2][\$c-2]*\$a[\$r-3][\$c-3];
30. \$max = \$result if \$result > \$max;
31. }
32. #forward diagonal
33. if(\$r >= 3 && \$c <= \$#{\$a[\$r]}-3){
34. \$result = \$a[\$r][\$c]*\$a[\$r-1][\$c+1]*\$a[\$r-2][\$c+2]*\$a[\$r-3][\$c+3];
35. \$max = \$result if \$result > \$max;
36. }
37. }
38. }
39.
40. print "\$max\n";
41.
42. close INFILE;