Files
advent_of_code_2021/02/part1.php
2021-12-03 19:25:51 +01:00

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