-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_2.php
More file actions
executable file
·51 lines (48 loc) · 1.07 KB
/
3_2.php
File metadata and controls
executable file
·51 lines (48 loc) · 1.07 KB
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
#!/usr/bin/php
<?php
error_reporting( -1 );
$end = 347991;
$a = array(); # map
$x = 0; # x coord
$y = 0; # y coord
$a[0][0] = 1;
while ( true ) {
do {
$x++; # move right
step();
} while ( isset( $a[$x][$y-1] ) );
do {
$y--; # move up
step();
} while ( isset( $a[$x-1][$y] ) );
do {
$x--; # move left
step();
} while ( isset( $a[$x][$y+1] ) );
do {
$y++; # move down
step();
} while ( isset( $a[$x+1][$y] ) );
}
function step() {
global $a, $x, $y, $end;
$a[$x][$y] = scan(); # set value
return;
}
function scan() {
global $a, $x, $y, $end;
$val = 0;
if ( isset( $a[$x][$y-1] ) ) $val += $a[$x][$y-1];
if ( isset( $a[$x][$y+1] ) ) $val += $a[$x][$y+1];
if ( isset( $a[$x-1][$y] ) ) $val += $a[$x-1][$y];
if ( isset( $a[$x+1][$y] ) ) $val += $a[$x+1][$y];
if ( isset( $a[$x-1][$y-1] ) ) $val += $a[$x-1][$y-1];
if ( isset( $a[$x+1][$y-1] ) ) $val += $a[$x+1][$y-1];
if ( isset( $a[$x-1][$y+1] ) ) $val += $a[$x-1][$y+1];
if ( isset( $a[$x+1][$y+1] ) ) $val += $a[$x+1][$y+1];
if ( $val > $end ) {
echo "value: $val\n";
exit;
}
return $val;
}