I didn't enjoy this, it ate my entire evening, and I'm sad that it looks like I'm going to have to come back to it on future days. I've tried to clean it up so it's less of a nightmare to return to, but...
$input=file_get_contents("input5.txt");$memory=explode(',',$input);run_intcode();functionrun_intcode(){global$memory;$pointer=0;$opcode_full="0000".$memory[$pointer];$opcode=substr($opcode_full,strlen($opcode_full)-2);while($opcode!=99){$param1_mode=$opcode_full[-3];$param2_mode=$opcode_full[-4];$p1=get_value($pointer+1,$param1_mode);$p2=get_value($pointer+2,$param2_mode);switch($opcode){case01:write_value($pointer+3,$p1+$p2);$pointer+=4;break;case02:write_value($pointer+3,$p1*$p2);$pointer+=4;break;case03:echo"enter the system ID number: ";$input_param=readline("enter the system to test: ");echo"\n";write_value($pointer+1,$input_param);$pointer+=2;break;case04:echo'output= '.$p1."\n";$pointer+=2;break;case05:if($p1!=0){$pointer=$p2;}else$pointer+=3;break;case06:if($p1==0){$pointer=$p2;}else$pointer+=3;break;case07:write_value($pointer+3,$p1<$p2?1:0);$pointer+=4;break;case'08':write_value($pointer+3,$p1==$p2?1:0);$pointer+=4;break;default:echo"nope\n";break;}$opcode_full="0000".$memory[$pointer];$opcode=substr($opcode_full,strlen($opcode_full)-2);}}functionget_value($position,$mode){global$memory;$value=$mode?$memory[$position]:$memory[$memory[$position]];return$value;}functionwrite_value($position,$value){global$memory;$memory[$memory[$position]]=$value;}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I didn't enjoy this, it ate my entire evening, and I'm sad that it looks like I'm going to have to come back to it on future days. I've tried to clean it up so it's less of a nightmare to return to, but...