27 lines
641 B
PHP
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];
|