public static int Part1Solution(long[] input) { /* * Items needed: * - Easter egg * - Mug * - Sand * - Space heater */ IntCodeProgram intCodeProgram = new IntCodeProgram(input); while (true) { string command = Console.ReadLine() + "\n"; foreach (var character in command) { intCodeProgram.Input.Enqueue(character); } var halt = intCodeProgram.Run(); while (intCodeProgram.Output.Count > 0) { Console.Write((char)intCodeProgram.Output.Dequeue()); } } return(0); }
public static long Part2Solution(long[] originalNumbersArray) { var memoryNumbersArray = new long[originalNumbersArray.Length]; bool found = false; long noun = 0; long verb = 0; for (var i = 0; i <= 99; i++) { for (var j = 0; j <= 99; j++) { originalNumbersArray.CopyTo(memoryNumbersArray, 0); memoryNumbersArray[1] = i; memoryNumbersArray[2] = j; IntCodeProgram intProgram = new IntCodeProgram(memoryNumbersArray); intProgram.Run(); if (intProgram.GetFirstPosition() == 19690720) { noun = i; verb = j; found = true; break; } } if (found) { break; } } return((100 * noun) + verb); }
public static long Part1Solution(long[] input) { var program = new IntCodeProgram(input); program.Run(); return(program.GetFirstPosition()); }
public static long Part1Solution(long[] input) { IntCodeProgram intCodeProgram = new IntCodeProgram(input); string[] commands = new string[] { "NOT A T\n", "OR T J\n", "NOT B T\n", "OR T J\n", "NOT C T\n", "OR T J\n", "AND D J\n", "WALK\n" }; foreach (var command in commands) { foreach (var character in command) { intCodeProgram.Input.Enqueue(character); } } intCodeProgram.Run(); while (intCodeProgram.Output.Count > 1) { Console.Write((char)intCodeProgram.Output.Dequeue()); } return(intCodeProgram.Output.Dequeue()); }
public static long Part2Solution(long[] input) { long currentScore = 0; long currentBlockTiles = -1; input[0] = 2; List <GridPosition> positions = new List <GridPosition>(); IntCodeProgram intCodeProgram = new IntCodeProgram(input); GridPosition horizontalPaddlePosition = new GridPosition(0, 0, Tile.HorizontalPaddle); GridPosition ballPosition = new GridPosition(0, 0, Tile.Ball); while (currentBlockTiles != 0) { intCodeProgram.Run(); (currentScore, ballPosition, horizontalPaddlePosition) = ProcessIntCodeOutput(positions, intCodeProgram); ProvideInput(intCodeProgram, ballPosition, horizontalPaddlePosition); currentBlockTiles = positions.Count(pos => pos.Tile == Tile.Block); } return(currentScore); }
public static long Part1Solution(long[] input) { var program = new IntCodeProgram(input, 1); program.Run(); return(program.Output.Last()); }
private static int FeedbackSet(long[] input, IntCodeProgram[] amplifiers, List <int> phaseSettingSequence) { for (int i = 0; i < amplifiers.Length; i++) { amplifiers[i] = new IntCodeProgram(input, phaseSettingSequence[i]); } amplifiers[0].Input.Enqueue(0); Queue <IntCodeProgram> amplifiersQueue = new Queue <IntCodeProgram>(amplifiers); Queue <long> nextInput = new Queue <long>(); while (amplifiersQueue.Count > 0) { IntCodeProgram amp = amplifiersQueue.Dequeue(); OutputToInput(nextInput, amp.Input); Halt haltType = amp.Run(); OutputToInput(amp.Output, nextInput); if (haltType == Halt.NeedInput) { amplifiersQueue.Enqueue(amp); } } return((int)nextInput.Single()); }
public static int Part1Solution(long[] input) { IntCodeProgram intCodeProgram = new IntCodeProgram(input); List <Position> positions = new List <Position>(); intCodeProgram.Run(); FillPositions(intCodeProgram.Output, positions); return(CalculateIntersections(positions)); }
public static long Part1Solution(long[] input) { List <GridPosition> positions = new List <GridPosition>(); IntCodeProgram intCodeProgram = new IntCodeProgram(input); intCodeProgram.Run(); ProcessIntCodeOutput(positions, intCodeProgram); return(positions.Count(position => position.Tile == Tile.Block)); }
private static void InitPrograms(this List <IntCodeProgram> intCodePrograms, long[] input) { for (var i = 0; i < 50; i++) { var intCodeProgram = new IntCodeProgram(input); intCodeProgram.Input.Enqueue(i); intCodeProgram.Run(); intCodePrograms.Add(intCodeProgram); } }
public static int Part2Solution(long[] input) { int paintedAtLeastOnce = 0; List <GridMark> gridMarks = new List <GridMark>(); var currentPosition = new GridMark(0, 0, Colors.Black); var currentDirection = Direction.Up; IntCodeProgram intCodeProgram = new IntCodeProgram(input); while (true) { if (gridMarks.Count == 0) { currentPosition.Color = Colors.White; } else { currentPosition.Color = GetPositionColor(currentPosition, gridMarks); } if (currentPosition.Color == Colors.Black) { intCodeProgram.Input.Enqueue(0); } else { intCodeProgram.Input.Enqueue(1); } var type = intCodeProgram.Run(); if (type == Halt.Terminated) { Print(gridMarks); return(paintedAtLeastOnce); } currentPosition.Color = (Colors)intCodeProgram.Output.Dequeue(); long directionToTurn = intCodeProgram.Output.Dequeue(); GridMark existingMark = gridMarks.SingleOrDefault(pos => pos.X == currentPosition.X && pos.Y == currentPosition.Y); if (existingMark != null) { gridMarks.Remove(existingMark); } else { paintedAtLeastOnce++; } gridMarks.Add(new GridMark(currentPosition.X, currentPosition.Y, currentPosition.Color)); currentDirection = SetDirection(currentDirection, directionToTurn); currentPosition = SetPosition(currentPosition, currentDirection); } }
public static int Part2Solution(long[] input) { input[0] = 2; IntCodeProgram intCodeProgram = new IntCodeProgram(input); long[] funcA = new long[] { (long)Ascii.Left, (long)Ascii.Comma, (long)Ascii.Four, (long)Ascii.Comma, (long)Ascii.Left, (long)Ascii.Comma, (long)Ascii.Four, (long)Ascii.Comma, (long)Ascii.Left, (long)Ascii.Comma, (long)Ascii.One, (long)Ascii.Zero, (long)Ascii.Comma, (long)Ascii.Right, (long)Ascii.Comma, (long)Ascii.Four, (long)Ascii.NewLine }; long[] funcB = new long[] { (long)Ascii.Right, (long)Ascii.Comma, (long)Ascii.Four, (long)Ascii.Comma, (long)Ascii.Left, (long)Ascii.Comma, (long)Ascii.One, (long)Ascii.Zero, (long)Ascii.Comma, (long)Ascii.Right, (long)Ascii.Comma, (long)Ascii.One, (long)Ascii.Zero, (long)Ascii.NewLine }; long[] funcC = new long[] { (long)Ascii.Right, (long)Ascii.Comma, (long)Ascii.Four, (long)Ascii.Comma, (long)Ascii.Left, (long)Ascii.Comma, (long)Ascii.Four, (long)Ascii.Comma, (long)Ascii.Left, (long)Ascii.Comma, (long)Ascii.Four, (long)Ascii.Comma, (long)Ascii.Right, (long)Ascii.Comma, (long)Ascii.Eight, (long)Ascii.Comma, (long)Ascii.Right, (long)Ascii.Comma, (long)Ascii.One, (long)Ascii.Zero, (long)Ascii.NewLine }; long[] orderFunctions = new long[] { (long)Ascii.A, (long)Ascii.Comma, (long)Ascii.C, (long)Ascii.Comma, (long)Ascii.A, (long)Ascii.Comma, (long)Ascii.B, (long)Ascii.Comma, (long)Ascii.A, (long)Ascii.Comma, (long)Ascii.B, (long)Ascii.Comma, (long)Ascii.C, (long)Ascii.Comma, (long)Ascii.B, (long)Ascii.Comma, (long)Ascii.B, (long)Ascii.Comma, (long)Ascii.C, (long)Ascii.NewLine }; //long[] askPrint = new long[] { (long)Ascii.y, (long)Ascii.NewLine }; // If we want to print result long[] askPrint = new long[] { (long)Ascii.n, (long)Ascii.NewLine }; long[] inputToProgram = orderFunctions.Concat(funcA.Concat(funcB.Concat(funcC.Concat(askPrint)))).ToArray(); foreach (var a in inputToProgram) { intCodeProgram.Input.Enqueue(a); } intCodeProgram.Run(); //FillPositions(intCodeProgram.Output, new List<Position>()); // Uncomment if want to print result return((int)intCodeProgram.Output.Last()); }
private static bool IsPulled(long[] input, int x, int y) { IntCodeProgram intCodeProgram = new IntCodeProgram(input); intCodeProgram.Input.Enqueue(x); intCodeProgram.Input.Enqueue(y); intCodeProgram.Run(); DroneState droneState = (DroneState)intCodeProgram.Output.Dequeue(); if (droneState == DroneState.Pulled) { Console.Write("#"); return(true); } else { Console.Write("."); return(false); } }
public Answer Move(Command command) { intCodeProgram.Input.Enqueue((long)command); intCodeProgram.Run(); return((Answer)intCodeProgram.Output.Dequeue()); }