Advertisement
Guest User

day2-part2-Intcode-calendar

a guest
Dec 3rd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1. for ($i=0; $i<99; $i++) {
  2.   for($z=0; $z<99; $z++) {
  3.       run($i, $z);
  4.   }
  5. }
  6.  
  7. function run($a, $b) {
  8.   $opcodes = [1,$a,$b,3,1,1,2,3,1,3,4,3,1,5,0,3,2,9,1,19,1,19,6,23,2,6,23,27,2,27,9,31,1,5,31,35,1,35,10,39,2,39,9,43,1,5,43,47,2,47,10,51,1,51,6,55,1,5,55,59,2,6,59,63,2,63,6,67,1,5,67,71,1,71,9,75,2,75,10,79,1,79,5,83,1,10,83,87,1,5,87,91,2,13,91,95,1,95,10,99,2,99,13,103,1,103,5,107,1,107,13,111,2,111,9,115,1,6,115,119,2,119,6,123,1,123,6,127,1,127,9,131,1,6,131,135,1,135,2,139,1,139,10,0,99,2,0,14,0];
  9.   $i = 0;
  10.   do {
  11.       $opcode = $opcodes[$i];
  12.      
  13.       $address1 = $opcodes[$i + 1];
  14.       $address2 = $opcodes[$i + 2];
  15.       $resultAdress = $opcodes[$i + 3];
  16.      
  17.       switch ($opcode) {
  18.               case 1:
  19.              
  20.                   // add
  21.                   $opcodes[$resultAdress] = $opcodes[$address1] + $opcodes[$address2];
  22.              
  23.                   break;
  24.               case 2:
  25.              
  26.                   // multiply
  27.                   $opcodes[$resultAdress] = $opcodes[$address1] * $opcodes[$address2];
  28.                  
  29.                   break;
  30.       }
  31.      
  32.       $i += 4;
  33.      
  34.   } while ($opcode != 99);
  35.  
  36.   if($opcodes[0] == 19690720) {
  37.       echo $opcodes[1] . "<br>" . $opcodes[2];
  38.   }
  39.  
  40.   // echo $opcodes[0];
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement