Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. using System;
  2.  
  3. namespace AdventOfCode002
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int[] data = { 1, 12, 2, 3,
  10. 1, 1, 2, 3,
  11. 1, 3, 4, 3,
  12. 1, 5, 0, 3,
  13. 2, 1, 13, 19,
  14. 1, 10, 19, 23,
  15. 2, 9, 23, 27,
  16. 1, 6, 27, 31,
  17. 1, 10, 31, 35,
  18. 1, 35, 10, 39,
  19. 1, 9, 39, 43,
  20. 1, 6, 43, 47,
  21. 1, 10, 47, 51,
  22. 1, 6, 51, 55,
  23. 2, 13, 55, 59,
  24. 1, 6, 59, 63,
  25. 1, 10, 63, 67,
  26. 2, 67, 9, 71,
  27. 1, 71, 5, 75,
  28. 1, 13, 75, 79,
  29. 2, 79, 13, 83,
  30. 1, 83, 9, 87,
  31. 2, 10, 87, 91,
  32. 2, 91, 6, 95,
  33. 2, 13, 95, 99,
  34. 1, 10, 99, 103,
  35. 2, 9, 103, 107,
  36. 1, 107, 5, 111,
  37. 2, 9, 111, 115,
  38. 1, 5, 115, 119,
  39. 1, 9, 119, 123,
  40. 2, 123, 6, 127,
  41. 1, 5, 127, 131,
  42. 1, 10, 131, 135,
  43. 1, 135, 6, 139,
  44. 1, 139, 5, 143,
  45. 1, 143, 9, 147,
  46. 1, 5, 147, 151,
  47. 1, 151, 13, 155,
  48. 1,5, 155, 159,
  49. 1, 2, 159, 163,
  50. 1, 163, 6, 0,
  51. 99, 2, 0, 14, 0 };
  52.  
  53.  
  54.  
  55. CalcIt(data);
  56. Console.ReadKey();
  57. }
  58.  
  59. static void CalcIt(int[] data)
  60. {
  61. int currentPos;
  62. int tempSum;
  63. int res;
  64. bool not99;
  65. int[] dataUse;
  66. int pos1counter = 0;
  67. int pos2counter = 0;
  68.  
  69. do
  70. {
  71. dataUse = data;
  72. dataUse[1] = pos1counter;
  73. dataUse[2] = pos2counter;
  74. currentPos = 0;
  75. tempSum = 0;
  76. res = 0;
  77. not99 = true;
  78.  
  79.  
  80. if (pos1counter >= pos2counter)
  81. pos2counter++;
  82. else
  83. pos1counter++;
  84.  
  85. Console.WriteLine(dataUse[0] + " - " + dataUse[1] + " - " + dataUse[2]);
  86. while (not99)
  87. {
  88. if (dataUse[currentPos] == 1)
  89. {
  90. currentPos++;
  91. tempSum = dataUse[dataUse[currentPos]] + dataUse[dataUse[++currentPos]];
  92. currentPos++;
  93. dataUse[dataUse[currentPos]] = tempSum;
  94. res += tempSum;
  95. tempSum = 0;
  96. currentPos++;
  97. }
  98. if (dataUse[currentPos] == 2)
  99. {
  100. currentPos++;
  101. tempSum = dataUse[dataUse[currentPos]] * dataUse[dataUse[++currentPos]];
  102. currentPos++;
  103. dataUse[dataUse[currentPos]] = tempSum;
  104. res += tempSum;
  105. tempSum = 0;
  106. currentPos++;
  107. }
  108. if (dataUse[currentPos] == 99)
  109. {
  110. not99 = false;
  111. }
  112. }
  113. Console.WriteLine(dataUse[0]);
  114. } while (dataUse[0] != 19690720);
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126. }
  127.  
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement