• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# day2-part1-Intcode-calendar

a guest Dec 3rd, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. \$opcodes = [1,12,2,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];
2.
3. \$i = 0;
4.
5. do {
6.   \$opcode = \$opcodes[\$i];
7.
8.   switch (\$opcode) {
9.       case 1:
11.
12.         \$pos1 = \$opcodes[\$i + 1];
13.         \$pos2 = \$opcodes[\$i + 2];
14.         \$pos3 = \$opcodes[\$i + 3];
15.         \$opcodes[\$pos3] = \$opcodes[\$pos1] + \$opcodes[\$pos2];
16.
17.         break;
18.       case 2:
19.         // multiply
20.
21.         \$pos1 = \$opcodes[\$i + 1];
22.         \$pos2 = \$opcodes[\$i + 2];
23.         \$pos3 = \$opcodes[\$i + 3];
24.         \$opcodes[\$pos3] = \$opcodes[\$pos1] * \$opcodes[\$pos2];
25.
26.         break;
27.   }
28.
29.   \$i += 4;
30.
31. } while (\$opcode != 99);
32.
33. echo \$opcodes[0];
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top