/
Euler_082.php
63 lines (56 loc) · 1.02 KB
/
Euler_082.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php $f=file('File.txt');foreach($f as $d=>$e){$f=explode(",", $e);foreach($f as $g=>$h)$a[$d][$g]=$h;}
$col_scan = 0;
for($f=0;$f<count($a);$f++)
{
for($g=0;$g<count($a);$g++)
{
if($f!=0)
{
$exist = 10000000000;
for($h=0;$h<count($a);$h++)
{
$d = $a[$h][$f-1];
$x = 0;
if($h<$g)
{
for($i=$h;$i<=$g;$i++)
{
$x = $x + $a[$i][$f];
}
$d = $d + $x;
if($d<=$exist)
$exist = $d;
}
if($h>$g)
{
for($i=$h;$i>=$g;$i--)
{
$x = $x + $a[$i][$f];
}
$d = $d + $x;
if($d<=$exist)
$exist = $d;
}
if($h==$g)
{
$d = $d + $a[$g][$f];
if($d<=$exist)
$exist = $d;
}
}
$r[$g]=$exist;
}
}
if($f!=0)
for($s=0;$s<count($a);$s++)
$a[$s][$col_scan]=$r[$s];
$col_scan++;
}
$exist=100000000000;
for($x=0;$x<count($a);$x++)
{
if($a[$x][count($a)-1]<=$exist)
$exist = $a[$x][count($a)-1];
}
echo $exist;
?>