50 lines
1.1 KiB
PHP
50 lines
1.1 KiB
PHP
<?php
|
|
|
|
// $input = "1,9,10,3,2,3,11,0,99,30,40,50";
|
|
$input = trim(file_get_contents("day2.txt"));
|
|
|
|
// echo $input."<hr>\n";
|
|
$input1 = explode(",", $input);
|
|
// var_dump($input1); die();
|
|
|
|
|
|
for($i = 0; $i < 100; $i++){
|
|
for($j = 0; $j < 100; $j++){
|
|
$input1 = explode(",", $input);
|
|
$input1[1] = $i;
|
|
$input1[2] = $j;
|
|
// die("n".count($input1));
|
|
$batchPos = 0;
|
|
while($batchPos < count($input1)){
|
|
if($input1[$batchPos] == 1){
|
|
$input1[$input1[$batchPos+3]] = $input1[$input1[$batchPos+1]] + $input1[$input1[$batchPos+2]];
|
|
}
|
|
if($input1[$batchPos] == 2){
|
|
$input1[$input1[$batchPos+3]] = $input1[$input1[$batchPos+1]] * $input1[$input1[$batchPos+2]];
|
|
}
|
|
elseif($input1[0] == 99){
|
|
break;
|
|
}
|
|
$batchPos += 4;
|
|
}
|
|
|
|
if($i == 12 && $j == 2){ echo "Part 1 output: ".$input1[0]."\n"; }
|
|
if($input1[0] == 19690720){ echo "Part 2 output: ". (100 * $i + $j); break; }
|
|
// if($i > 1){ break; }
|
|
|
|
}
|
|
}
|
|
|
|
die();
|
|
|
|
|
|
foreach($input1 as $key => $value){
|
|
echo $value;
|
|
if(!(($key+1) % 4) && $key != 0){ echo "\n"; }
|
|
else{ echo ","; }
|
|
}
|
|
die();
|
|
|
|
die(implode(",",$input1));
|
|
print_r($input1);
|