Advertisement
Skske

advent of code day 2

Dec 12th, 2019
1,241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var array1 = 0
  2. var array2 = 0
  3. var testarray = [1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,9,19,1,5,19,23,1,6,23,27,1,27,10,31,1,31,5,35,2,10,35,39,1,9,39,43,1,43,5,47,1,47,6,51,2,51,6,55,1,13,55,59,2,6,59,63,1,63,5,67,2,10,67,71,1,9,71,75,1,75,13,79,1,10,79,83,2,83,13,87,1,87,6,91,1,5,91,95,2,95,9,99,1,5,99,103,1,103,6,107,2,107,13,111,1,111,10,115,2,10,115,119,1,9,119,123,1,123,9,127,1,13,127,131,2,10,131,135,1,135,5,139,1,2,139,143,1,143,5,0,99,2,0,14,0]
  4. while (testarray[1]<99) {
  5.   testarray = [1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,9,19,1,5,19,23,1,6,23,27,1,27,10,31,1,31,5,35,2,10,35,39,1,9,39,43,1,43,5,47,1,47,6,51,2,51,6,55,1,13,55,59,2,6,59,63,1,63,5,67,2,10,67,71,1,9,71,75,1,75,13,79,1,10,79,83,2,83,13,87,1,87,6,91,1,5,91,95,2,95,9,99,1,5,99,103,1,103,6,107,2,107,13,111,1,111,10,115,2,10,115,119,1,9,119,123,1,123,9,127,1,13,127,131,2,10,131,135,1,135,5,139,1,2,139,143,1,143,5,0,99,2,0,14,0]
  6.   testarray[1] = array1
  7.   testarray[2] = array2
  8.   for (i = 0; i < testarray.length; i+=4) {
  9.     if(testarray[i]==99) {
  10.       break;
  11.     } else if(testarray[i]==1){
  12.       testarray[testarray[i+3]] = testarray[testarray[i+1]] + testarray[testarray[i+2]]
  13.     } else if(testarray[i]==2) {
  14.        testarray[testarray[i+3]] = testarray[testarray[i+1]] * testarray[testarray[i+2]]
  15.     }
  16.   }
  17.   if(testarray[0] == 19690720) {
  18.     break;
  19.   }
  20.   var array2 = array2 + 1
  21.   if(testarray[2]>99){
  22.     array2 = 0;
  23.     array1 = array1 + 1;
  24.   }
  25. }
  26. console.log(testarray[0])
  27. console.log(testarray[1])
  28. console.log(testarray[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement