private static long InternalStep2(string s) { return(new long[] { 5, 6, 7, 8, 9 }.Permute() .Max(permutation => { var machines = permutation .Select((phase, index) => { var machine = new IntCodeMachine(s.ToLongArray()); machine.Run(phase); return machine; }).ToArray(); long tail = 0; while (machines.Last().Status != IntCodeStatus.Stopped) { machines.ForEach(m => { m.Run(tail); tail = m.Outputs.Last(); }); } machines.Select(it => it.Status).Should().AllBeEquivalentTo(IntCodeStatus.Stopped); return tail; })); }
public static void ExecuteStarTwo(string fileLocation = "PuzzleInput/Day9.txt") { long[] program = File.ReadAllText(fileLocation).Split(',').Select(long.Parse).ToArray(); long[] input = new List <long>() { 2 }.ToArray(); IntCodeMachine icm = new IntCodeMachine(program, input); icm.Run(); Logger.LogMessage(LogLevel.ANSWER, "9A: BOOST Coordinates: " + icm.Output); }
public static void ExecuteStarOne(string fileLocation = "PuzzleInput/Day5.txt") { string line = File.ReadAllText(fileLocation); var input = new long[1] { 1 }; IntCodeMachine machine = new IntCodeMachine(Array.ConvertAll(line.Split(','), long.Parse), input); machine.Run(); Logger.LogMessage(LogLevel.ANSWER, "5A: Machine Output: " + machine.Output); }
public void Run() { a.EnterInput(0); a.Run(); b.EnterInput((int)a.GetNextOutput()); b.Run(); c.EnterInput((int)b.GetNextOutput()); c.Run(); d.EnterInput((int)c.GetNextOutput()); d.Run(); e.EnterInput((int)d.GetNextOutput()); e.Run(); while (e.IsRunning) { a.EnterInput((int)e.GetNextOutput()); b.EnterInput((int)a.GetNextOutput()); c.EnterInput((int)b.GetNextOutput()); d.EnterInput((int)c.GetNextOutput()); e.EnterInput((int)d.GetNextOutput()); } this.Output = (int)e.GetNextOutput(); }
public void Run() { icm.Run(); while (icm.IsRunning) { while (icm.Output.Count > 0) { long x = icm.GetNextOutput(); long y = icm.GetNextOutput(); long id = icm.GetNextOutput(); if (x == -1 && y == 0) { CurrentScore = id; } else { var t = Tiles.FirstOrDefault(t => t.X == x && t.Y == y); if (t == null) { Tiles.Add(new Tile(x, y, id)); } else { t.TileId = id; } } } PrintTiles(); if (icm.IsRunning) { Logger.LogMessage(LogLevel.ANSWER, "L/R/N: "); //string i = Console.ReadLine(); string i; if (Logger.CURRENT_LOG_LEVEL == LogLevel.DEBUG) { i = Console.ReadLine(); } else { var ball = Tiles.First(t => t.TileId == 4); var paddle = Tiles.First(t => t.TileId == 3); if (ball.X > paddle.X) { i = "R"; } else if (ball.X < paddle.X) { i = "L"; } else { i = "N"; } } if (i == "L") { icm.EnterInput(-1); } else if (i == "R") { icm.EnterInput(1); } else { icm.EnterInput(0); } } } while (icm.Output.Count > 0) { long x = icm.GetNextOutput(); long y = icm.GetNextOutput(); long id = icm.GetNextOutput(); if (x == -1 && y == 0) { CurrentScore = id; } else { var t = Tiles.FirstOrDefault(t => t.X == x && t.Y == y); if (t == null) { Tiles.Add(new Tile(x, y, id)); } else { t.TileId = id; } } } PrintTiles(); }