advent_of_code_2019/day_2/part_1.php
2019-12-06 14:32:52 +01:00

27 lines
641 B
PHP

<?php
$input = explode(',', file_get_contents('input.txt'));
// don't forget : 12 @ position 1 && 2 @ position 2
$i = 0;
while($input[$i] !== 99) {
[$operation, $first, $second, $position] = array_slice($input, $i, 4);
switch ($operation) {
case 1:
$input[$position] = $input[$first] + $input[$second];
break;
case 2:
$input[$position] = $input[$first] * $input[$second];
break;
case 99:
echo $input[0];
exit;
default:
echo 'unknown operation : '.$operation;
exit;
}
$i += 4;
}
echo $input[0];