public void Star2() { _input = FileHelpers.Read(_filePath); _parsedInput = _parser.Parse(_input); var solution = _solver.Star2(_parsedInput); Console.WriteLine(solution); Assert.AreEqual(532, solution); }
public void Part1() { var a = (int[])Day5Input.Clone(); var i = 0; var op = a[i] % 100; while (op != 99) { var modes = a[i] / 100; switch (op) { case 1: var term11 = modes % 10 == 1 ? a[i + 1] : a[a[i + 1]]; modes /= 10; var term12 = modes % 10 == 1 ? a[i + 2] : a[a[i + 2]]; a[a[i + 3]] = term11 + term12; i += 4; break; case 2: var term21 = modes % 10 == 1 ? a[i + 1] : a[a[i + 1]]; modes /= 10; var term22 = modes % 10 == 1 ? a[i + 2] : a[a[i + 2]]; a[a[i + 3]] = term21 * term22; i += 4; break; case 3: a[a[i + 1]] = 1; i += 2; break; case 4: var output = modes % 10 == 1 ? a[i + 1] : a[a[i + 1]]; TestContext.WriteLine(output.ToString()); i += 2; break; } op = a[i] % 100; } }
public void Part2() { var a = (int[])Day5Input.Clone(); var i = 0; var op = a[i] % 100; while (op != 99) { var modes = a[i] / 100; switch (op) { case 1: var term11 = modes % 10 == 1 ? a[i + 1] : a[a[i + 1]]; modes /= 10; var term12 = modes % 10 == 1 ? a[i + 2] : a[a[i + 2]]; a[a[i + 3]] = term11 + term12; i += 4; break; case 2: var term21 = modes % 10 == 1 ? a[i + 1] : a[a[i + 1]]; modes /= 10; var term22 = modes % 10 == 1 ? a[i + 2] : a[a[i + 2]]; a[a[i + 3]] = term21 * term22; i += 4; break; case 3: a[a[i + 1]] = 5; i += 2; break; case 4: var output = modes % 10 == 1 ? a[i + 1] : a[a[i + 1]]; TestContext.WriteLine(output.ToString()); i += 2; break; case 5: var param51 = modes % 10 == 1 ? a[i + 1] : a[a[i + 1]]; if (param51 != 0) { modes /= 10; var param52 = modes % 10 == 1 ? a[i + 2] : a[a[i + 2]]; i = param52; } else { i += 3; } break; case 6: var param61 = modes % 10 == 1 ? a[i + 1] : a[a[i + 1]]; if (param61 == 0) { modes /= 10; var param62 = modes % 10 == 1 ? a[i + 2] : a[a[i + 2]]; i = param62; } else { i += 3; } break; case 7: var param71 = modes % 10 == 1 ? a[i + 1] : a[a[i + 1]]; modes /= 10; var param72 = modes % 10 == 1 ? a[i + 2] : a[a[i + 2]]; a[a[i + 3]] = param71 < param72 ? 1 : 0; i += 4; break; case 8: var param81 = modes % 10 == 1 ? a[i + 1] : a[a[i + 1]]; modes /= 10; var param82 = modes % 10 == 1 ? a[i + 2] : a[a[i + 2]]; a[a[i + 3]] = param81 == param82 ? 1 : 0; i += 4; break; } op = a[i] % 100; } }
public void SetUp() { _solver = new Day5Solver(); _input = new Day5Input(); }