3rd and 2nd day
This commit is contained in:
15
02/part1.php
Normal file
15
02/part1.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?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
|
||||
23
02/part2.php
Normal file
23
02/part2.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?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
|
||||
Reference in New Issue
Block a user