-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd11_1_2.php
45 lines (37 loc) · 850 Bytes
/
d11_1_2.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
<?php
// http://keekerdc.com/2011/03/hexagon-grids-coordinate-systems-and-distance-calculations/
$moves = explode(',', file_get_contents('input_d11.txt'));
$x = $y = $z = 0;
$max = 0;
foreach ($moves as $move) {
switch (trim($move)) {
case 'n':
$y++;
$z--;
break;
case 'ne':
$x++;
$z--;
break;
case 'se';
$x++;
$y--;
break;
case 's':
$y--;
$z++;
break;
case 'sw':
$x--;
$z++;
break;
case 'nw':
$x--;
$y++;
break;
}
$max = max($x, $y, $z, $max);
}
echo $x . ':' . $y . ':' . $z . PHP_EOL;
echo 'Distance: ' . max($x, $y, $z) . PHP_EOL;
echo 'Max: ' . $max . PHP_EOL;