🎉 Hello world
This commit is contained in:
26
day_2/part_1.php
Normal file
26
day_2/part_1.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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];
|
||||
Reference in New Issue
Block a user