24 lines
563 B
PHP
24 lines
563 B
PHP
<?php
|
|
|
|
$increased = 0;
|
|
$inputStream = fopen('input', 'r');
|
|
$horizontal = $depth = $aim = 0;
|
|
|
|
while (($line = fgets($inputStream)) !== false) {
|
|
[$instruction, $value] = explode(' ', trim($line));
|
|
$value = (int)$value;
|
|
switch ($instruction) {
|
|
case 'down':
|
|
$aim += $value;
|
|
break;
|
|
case 'up':
|
|
$aim -= $value;
|
|
break;
|
|
case 'forward':
|
|
$horizontal += $value;
|
|
$depth += $value * $aim;
|
|
break;
|
|
}
|
|
}
|
|
echo $depth * $horizontal; // 1781819478
|