16 lines
398 B
PHP
16 lines
398 B
PHP
<?php
|
|
|
|
$increased = 0;
|
|
$inputStream = fopen('input', 'r');
|
|
$horizontal = $depth = 0;
|
|
|
|
while (($line = fgets($inputStream)) !== false) {
|
|
[$instruction, $value] = explode(' ', trim($line));
|
|
match ($instruction) {
|
|
'down' => $depth += (int)$value,
|
|
'up' => $depth -= (int)$value,
|
|
'forward' => $horizontal += (int)$value,
|
|
};
|
|
}
|
|
echo $depth * $horizontal; // 1635930
|