static Object PartB() { List <long> input = ReadInput(); IntComputer c1 = new IntComputer(input, 0); PosComputer p1 = new PosComputer(c1); OurMap m = BuildMap(p1, false); int b = CalculateOxygenFillMinutes(m); Console.WriteLine("Part B: Result is {0}", b); return(b); }
static bool PartB(Object correctAnswer = null) { List <long> input = ReadInput(); IntComputer c1 = new IntComputer(input, 0); PosComputer p1 = new PosComputer(c1); OurMap m = BuildMap(p1, false); int b = CalculateOxygenFillMinutes(m); Console.WriteLine("Part B: Result is {0}", b); return(correctAnswer == null || b == (int)correctAnswer); }
static Object PartA() { List <long> input = ReadInput(); IntComputer c1 = new IntComputer(input, 0); PosComputer p1 = new PosComputer(c1); OurMap m = BuildMap(p1, true); Console.SetCursorPosition(0, 1); m.PrintMap(); int ans = CalculateStepsToTreasure(m); Console.WriteLine("Part A: Result is {0}", ans); return(ans); }
static OurMap BuildMap(PosComputer c1, bool print) { OurMap m = new OurMap(); List <PosComputer> computers = new List <PosComputer>(); SetupComputerMovement(ref c1, 0); computers.Add(c1); do { List <PosComputer> newComputers = new List <PosComputer>(); foreach (PosComputer c in computers) { if (c.ic.Execute()) { // 0 = Hit wall, 1 = Has moved, 2 = Has moved, found treasure int res = (int)c.ic.reg; m.mapPos[c.nextPos] = res; if (res > 0) { c.curPos = c.nextPos; } // Movement command values: 1 = N, 2 = S, 3 = W, 4 = E for (int i = 0; i < directions.Count; i++) { Position newPos = c.curPos + directions[i]; if (!m.mapPos.ContainsKey(newPos)) { PosComputer x = new PosComputer(c); SetupComputerMovement(ref x, i); newComputers.Add(x); } } } } computers = newComputers; if (print) { Console.SetCursorPosition(0, 1); m.PrintMap(); } }while (computers.Count > 0); return(m); }
public PosComputer(PosComputer pc) { ic = new IntComputer(pc.ic); curPos = pc.curPos; nextPos = pc.nextPos; }
static void SetupComputerMovement(ref PosComputer c, int dirIndex) { c.ic.reg = dirIndex + 1; c.nextPos = c.curPos + directions[dirIndex]; }