public void RunPart2() { string[] lines = File.ReadAllLines("Data/Day13.txt"); string line = lines[0]; Int64[] numbers; numbers = line.Split(',').Select(x => Int64.Parse(x)).ToArray(); Array.Resize(ref numbers, numbers.Length * 10); numbers[0] = 2; amplifier = new Amplifier('A', numbers, this); writeLineNumber = Console.CursorTop; while (!amplifier.IsDone) { var instructions = amplifier.Calculate(); if (!amplifier.IsDone) { doMove(instructions); } } Console.WriteLine("Part 2: " + score); //this.print(); }
public void RunPart1() { string[] lines = File.ReadAllLines("Data/Day11.txt"); string line = lines[0]; Int64[] numbers; numbers = line.Split(',').Select(x => Int64.Parse(x)).ToArray(); Array.Resize(ref numbers, numbers.Length * 10); amplifier = new Amplifier('A', numbers); while (!amplifier.IsDone) { this.amplifier.Inputs.Add(board[positionX, positionY] == 1 ? 1 : 0); var instructions = amplifier.Calculate(); if (!amplifier.IsDone) { doMove(instructions); } } Console.WriteLine("Part 1: " + panelCounter); }
public void RunPart2() { string[] lines = File.ReadAllLines("Data/Day09.txt"); string line = lines[0]; Int64[] numbers; numbers = line.Split(',').Select(x => Int64.Parse(x)).ToArray(); Array.Resize(ref numbers, numbers.Length * 10); Amplifier amplifier = new Amplifier('A', numbers); amplifier.Inputs.Add(2); amplifier.Calculate(); Console.WriteLine("Part 2: " + amplifier.Output); }
public void RunPart2() { string[] lines = File.ReadAllLines("Data/Day11.txt"); string line = lines[0]; Int64[] numbers; numbers = line.Split(',').Select(x => Int64.Parse(x)).ToArray(); Array.Resize(ref numbers, numbers.Length * 10); Console.WriteLine("Part 2: "); for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { board[x, y] = 1; } } amplifier = new Amplifier('A', numbers); while (!amplifier.IsDone) { this.amplifier.Inputs.Add(board[positionX, positionY] == 1 ? 1 : 0); var instructions = amplifier.Calculate(); if (!amplifier.IsDone) { doMove(instructions); } } for (int y = 68; y < 107; y++) { string writeLine = ""; for (int x = 70; x < 76; x++) { writeLine += board[x, y] == 1 ? "X" : " "; } Console.WriteLine(writeLine); } }
public void RunPart1() { string[] lines = File.ReadAllLines("Data/Day09.txt"); //lines = new string[] { "109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99" }; //lines = new string[] { "1102,34915192,34915192,7,4,7,99,0" }; //lines = new string[] { "104,1125899906842624,99" }; string line = lines[0]; Int64[] numbers; numbers = line.Split(',').Select(x => Int64.Parse(x)).ToArray(); Array.Resize(ref numbers, numbers.Length * 10); Amplifier amplifier = new Amplifier('A', numbers); amplifier.Inputs.Add(1); amplifier.Calculate(); Console.WriteLine("Part 1: " + amplifier.Output); }
private void doMoves(State[,] board, long size, int cursorTop, ref long currentX, ref long currentY, ref long previousX, ref long previousY, Amplifier amplifier, List <Tuple <long, long, int, Direction> > stepsOnPath, ref int maxPath, ref int maxPathCurrent, bool print, bool part1) { while (true) { State north = board[currentX, currentY - 1]; State east = board[currentX + 1, currentY]; State south = board[currentX, currentY + 1]; State west = board[currentX - 1, currentY]; int amountOfWays = 0; if (north == State.Way) { amountOfWays++; } if (east == State.Way) { amountOfWays++; } if (south == State.Way) { amountOfWays++; } if (west == State.Way) { amountOfWays++; } Direction directionToGo; if (north == State.Unknown) { directionToGo = Direction.N; } else if (east == State.Unknown) { directionToGo = Direction.E; } else if (south == State.Unknown) { directionToGo = Direction.S; } else if (west == State.Unknown) { directionToGo = Direction.W; } else { // No where to go (means that part 2 is finished) if (amountOfWays == 0) { break; } // Dead end else if (amountOfWays == 1) { if (maxPathCurrent > maxPath) { maxPath = maxPathCurrent; } Tuple <long, long, int, Direction> previousStep = stepsOnPath.LastOrDefault(); if (previousStep != null) { board[previousStep.Item1, previousStep.Item2] = State.DeadEnd; stepsOnPath.Remove(previousStep); maxPathCurrent -= 2; } if (north == State.Way) { directionToGo = Direction.N; } else if (east == State.Way) { directionToGo = Direction.E; } else if (south == State.Way) { directionToGo = Direction.S; } else if (west == State.Way) { directionToGo = Direction.W; } else { throw new NotSupportedException(); } } else { // Moved up or down from last move if (currentX == previousX) { // Last move was move to the top if (previousY > currentY) { directionToGo = Direction.N; } // Last move was move to the bottom else { directionToGo = Direction.S; } } // Moved left or right from last move else { // Last move was move to the left if (previousX > currentX) { directionToGo = Direction.W; } // Last move was move to the right else { directionToGo = Direction.E; } } } } amplifier.Inputs.Add((int)directionToGo); amplifier.Calculate(); Tuple <long, long, bool> result = this.finishMovement(board, stepsOnPath, amountOfWays, currentX, currentY, directionToGo, amplifier.Output); if (previousX != currentX || previousY != currentY) { maxPathCurrent++; } previousX = currentX; previousY = currentY; currentX = result.Item1; currentY = result.Item2; if (part1) { // Station found if (result.Item3) { break; } } if (print) { this.print(board, size, currentX, currentY, cursorTop, maxPath, maxPathCurrent); Thread.Sleep(100); } } }