25 lines
581 B
PHP
25 lines
581 B
PHP
<?php
|
||
|
||
$instructions = explode("\n", file_get_contents('input.txt'));
|
||
|
||
$position = 0;
|
||
$depth = 0;
|
||
$aim = 0;
|
||
|
||
foreach ($instructions as $instruction) {
|
||
[$movement, $value] = explode(' ', $instruction);
|
||
switch ($movement) {
|
||
case 'forward':
|
||
$position += $value;
|
||
$depth += $aim * $value;
|
||
break;
|
||
case 'up':
|
||
$aim -= $value;
|
||
break;
|
||
case 'down':
|
||
$aim += $value;
|
||
break;
|
||
}
|
||
}
|
||
|
||
echo sprintf('horizontal position %s × depth %s = %s', $position, $depth, $position * $depth); |