static void Main(string[] args) { var puzzleInput = puzzleInputToList(Constants.INPUT_FILENAME); Intcode i = new Intcode(puzzleInput); var outputString = String.Empty; while (!i.hasFinished) { var output = i.Run(); var convertedOutput = asciiToChar(output); outputString = String.Concat(outputString, convertedOutput); } var test = outputString.Split("\n"); var height = test.Length - 2; char[][] chArray = new char[height - 1][]; for (int j = 0; j < height - 1; j++) { chArray[j] = test[j].ToCharArray(); } foreach (var p in chArray) { Console.WriteLine(String.Join("", p)); } // Console.WriteLine(calculateSumForPartOne(chArray)); // Identify coordinates where scaffold char is surrounded by other scaffold chars // Print out coordinate of current position marker var tupleCurrPosn = currPosnMarker(chArray); Console.WriteLine($"{tupleCurrPosn.Item1}, {tupleCurrPosn.Item2}"); }
private IntType SolveFor(IntType input) { var lines = File.ReadAllLines(Input, Encoding.UTF8); var start = Intcode.ParseInput(lines[0]); return(RunProgram(ref start, input).Value); }
static int fewestMovesToOxygen(List <long> puzzleInput, List <List <int> > startingList) { long xPosn = 0; int count = 0; while (xPosn != 2) { buildUpFunction(startingList); foreach (var inputValue in new List <List <int> >(startingList)) { count = 0; Intcode i = new Intcode(puzzleInput, inputValue); while (!i.hasFinished) { xPosn = i.Run(); count++; if (xPosn != 1) { if (!i.hasFinished) // This is required if xPosn is 0 { startingList.Remove(inputValue); } if (xPosn == 2) { Console.WriteLine(String.Join(",", inputValue)); } break; } } } } return(count); }
public void FindingOutput19690720() { string program = File.ReadAllText("Input.txt"); long desiredOutput = 19690720; for (long noun = 10; noun < 100; noun++) { for (long verb = 10; verb < 100; verb++) { var intcode = new Intcode(program); intcode.WriteMemory(1, noun); intcode.WriteMemory(2, verb); intcode.Process(); if (intcode.Result == desiredOutput) { _output.WriteLine($"Found noun: {noun} and verb: {verb}; The result is {100 * noun + verb}"); return; } } } Assert.True(false, "Failed to find noun and verb for desired output :("); }
static void Main(string[] args) { decimal sum = ComputeModuleSum(); Console.WriteLine($"Module sum: {sum}"); Intcode intcode = ComputeIntCode(); Console.WriteLine($"Intcode: {intcode.Compute()}"); for (var i = 0; i <= 99; i++) { for (var j = 0; j <= 99; j++) { intcode.Reset(); intcode.Intcodes[1] = i; intcode.Intcodes[2] = j; int output = intcode.Compute(); if (output == 19690720) { int nounVerb = 100 * i + j; Console.WriteLine($"Noun + Verb: {nounVerb}"); break; } } } int closestIntersection = ComputeClosestIntersection(); Console.WriteLine($"Closest intersection: {closestIntersection}"); Console.ReadLine(); }
private bool ProveA1() { var input = "109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99"; var program = Intcode.ParseInput(input); var state = new Intcode.State(program); var outputs = new List <IntType>(); while (Intcode.Step(state)) { if (state.output.HasValue) { var output = state.PopOutput(); if (output.HasValue) { outputs.Add(output.Value); } } } var final = string.Join(",", outputs); if (final != input) { Console.WriteLine(); Console.WriteLine($"Input: {input}"); Console.WriteLine($"Final: {final}"); return(false); } return(true); }
static void Main(string[] args) { var puzzleInput = puzzleInputToList(Constants.INPUT_FILENAME); Intcode i = new Intcode(puzzleInput); i.Run(); }
public bool ProveB() { string[] lines = File.ReadAllLines(ExampleB, Encoding.UTF8); var tests = new Dictionary <IntType, IntType>(); tests[7] = 999; tests[8] = 1000; tests[9] = 1001; foreach (var line in lines) { var inputs = line.Split(" "); var input = IntType.Parse(inputs[0]); var expected = IntType.Parse(inputs[1]); var program = Intcode.ParseInput(inputs[2]); var output = RunProgram(ref program, input); if (output != expected) { Console.WriteLine(); Console.WriteLine($" Line: {inputs[2]}"); Console.WriteLine($" Input: {input}"); Console.WriteLine($" Expected: {expected}"); Console.WriteLine($" Actual: {output}"); return(false); } } return(true); }
public string SolveA() { var lines = File.ReadAllLines(Input, Encoding.UTF8); var program = Intcode.ParseInput(lines[0]); var computerBank = new Computer[50]; const int numComputers = 50; long?answer = null; Action <PacketToSend> packetSender = (PacketToSend packet) => { if (packet.Destination == 255) { answer = packet.ToSend.Y; } else { computerBank[packet.Destination].QueuePacket(packet.ToSend); } }; for (int i = 0; i < numComputers; i++) { computerBank[i] = new Computer(i, program, packetSender); } while (!answer.HasValue) { foreach (var computer in computerBank) { computer.Step(); } } return(answer.Value.ToString()); }
static void Main() { int[] memory = Input.PuzzleInput; string[] phaseSequences = Input.allPhases; int maxOutput = 0; Intcode ampA = new Intcode(memory); Intcode ampB = new Intcode(memory); Intcode ampC = new Intcode(memory); Intcode ampD = new Intcode(memory); Intcode ampE = new Intcode(memory); foreach (string phaseSequence in phaseSequences) { int[] phaseSettings = Array.ConvertAll(phaseSequence.ToCharArray(), x => int.Parse(x.ToString())); int outputA = ampA.Run(0, phaseSettings[0]); int outputB = ampB.Run(outputA, phaseSettings[1]); int outputC = ampC.Run(outputB, phaseSettings[2]); int outputD = ampD.Run(outputC, phaseSettings[3]); int finalOutput = ampE.Run(outputD, phaseSettings[4]); maxOutput = Math.Max(maxOutput, finalOutput); } Console.WriteLine(maxOutput); }
public string execute(string[] instructions) { var lines = File.ReadAllLines(Input, Encoding.UTF8); var program = Intcode.ParseInput(lines[0]); var state = new Intcode.State(program); var input = string.Join('\n', instructions); var ascii = new List <long>(); var index = 0; while (Intcode.Step(state)) { var output = state.PopOutput(); if (output.HasValue) { ascii.Add(output.Value); } if (!state.input.HasValue && index < input.Length) { state.input = input[index++]; } } var lastVal = ascii[ascii.Count - 1]; if (lastVal < char.MaxValue) { var asciiText = ascii.Select(a => (char)a).Take(ascii.Count - 1); Console.WriteLine(string.Join("", asciiText)); return("Sad death"); } return(lastVal.ToString()); }
public string SolveFor(int input) { var lines = File.ReadAllLines(Input, Encoding.UTF8); var program = Intcode.ParseInput(lines[0]); var state = new Intcode.State(program, input); var outputs = new List <IntType>(); while (Intcode.Step(state)) { if (state.output.HasValue) { var output = state.PopOutput(); if (output.HasValue) { outputs.Add(output.Value); } } } if (outputs.Count == 1) { return(outputs[0].ToString()); } // FAILED Console.WriteLine(string.Join(",", outputs)); throw new Exception("Day 9, Solve A failed"); }
public void ItExists() { int[] intcodes = new int[] { 1, 0, 0, 3, 99 }; var intcode = new Intcode(intcodes); int result = intcode.Compute(); }
public string SolveA() { var lines = File.ReadAllLines(Input, Encoding.UTF8); var program = Intcode.ParseInput(lines[0]); var state = new Intcode.State(program); var ascii = new StringBuilder(); while (Intcode.Step(state)) { var output = state.PopOutput(); if (output.HasValue) { var v = OutputToValue(output.Value); if (v.HasValue) { ascii.Append(v.Value); } } } var asciiText = ascii.ToString(); // OutputAscii(asciiText); var environment = asciiText.Split(new[] { newLine }); environment = environment.Where(e => e.Length > 0).ToArray(); var answer = AlignmentValue(environment); return(answer.ToString()); }
private (string raw, List <string> doors, List <string> items) RunStep(Intcode ic, string input, List <string> inventory) { if (input != null) { foreach (var c in input) { ic.Input.Enqueue(c); } ic.Input.Enqueue('\n'); } ic.Run(); var output = string.Join("", ic.Output.Select(x => (char)x)); ic.Output.Clear(); if (console) { Console.WriteLine("INPUT: " + input); Console.WriteLine("OUTPUT: " + output); Console.WriteLine("INVENTORY: " + string.Join(", ", inventory)); Console.WriteLine(new string('-', 80) + '\n'); } var spl = output.Split('\n'); var doors = new List <string>(); var items = new List <string>(); for (int i = 0; i < spl.Length;) { if (spl[i].StartsWith("Items here:")) { while (spl[++i].StartsWith("- ")) { items.Add(spl[i].Substring(2)); } } else if (spl[i].StartsWith("Doors here lead:")) { while (spl[++i].StartsWith("- ")) { doors.Add(spl[i].Substring(2)); } } else if (spl[i].Contains("you are ejected back to the checkpoint")) { doors.Clear(); items.Clear(); i++; } else { i++; } } return(raw : output, doors, items); }
private void Initialise() { _ascii = Intcode.LoadFromFile("Day17/ASCII.txt"); _asciiInput = new IOPipe(); _asciiOutput = new IOPipe(); _ascii.SetOutput(_asciiOutput); _ascii.SetInput(_asciiInput); }
public void Output16DigitsNumber() { var intcode = new Intcode("1102,34915192,34915192,7,4,7,99,0"); intcode.Process(); Assert.Equal(16, intcode.Output.ToString().Length); }
public void TestLargerProgram(long input, long expectedOutput) { var intcode = new Intcode("3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,1106, 0, 36, 98, 0, 0, 1002, 21, 125, 20, 4, 20, 1105, 1, 46, 104,999, 1105, 1, 46, 1101, 1000, 1, 20, 4, 20, 1105, 1, 46, 98, 99", input); intcode.Process(); Assert.Equal(expectedOutput, intcode.Output); }
public void OutputLargeNumber() { var intcode = new Intcode("104,1125899906842624,99"); intcode.Process(); Assert.Equal(1125899906842624, intcode.Output); }
public void Calculate(string program, string expectedOutput) { var intcode = new Intcode(program); intcode.Process(); Assert.StartsWith(expectedOutput, intcode.GetMemoryDump()); }
public void TestNewIntructions() { var intcode = new Intcode("3,0,4,0,99", 42); intcode.Process(); Assert.Equal(42, intcode.Output); }
private void InitialiseDrone() { _droneController = Intcode.LoadFromFile("Day19/DroneController.txt"); _droneInput = new IOPipe(); _droneOutput = new IOPipe(); _droneController.SetInput(_droneInput); _droneController.SetOutput(_droneOutput); }
public void TestJumps(string program, long input, long expectedOutput) { var intcode = new Intcode(program, input); intcode.Process(); Assert.Equal(expectedOutput, intcode.Output); }
public void TestNewOpcodeFormat() { var intcode = new Intcode("1002,4,3,4,33"); intcode.Process(); Assert.Equal(1002, intcode.Result); Assert.Equal(99, intcode.ReadMemory(0)); }
private string executeCommands(Intcode.State state, string[] commands, bool assumePrompt) { var lastLine = new StringBuilder(); var commandOutput = new StringBuilder(); var commandIndex = 0; var input = ""; if (assumePrompt) { commandIndex++; input = commands[0] + "\n"; } var index = 0; while (Intcode.Step(state)) { var output = state.PopOutput(); if (output.HasValue) { char c = (char)output.Value; fullTrace.Append(c); commandOutput.Append(c); switch (c) { case '\n': if (lastLine.ToString() == "Command?") { if (commandIndex < commands.Length) { input = commands[commandIndex++]; fullTrace.Append($"> {input}\n"); } else { // We are done return(commandOutput.ToString()); } input += '\n'; index = 0; } lastLine.Clear(); break; default: lastLine.Append(c); break; } } if (!state.input.HasValue && index < input.Length) { state.input = input[index++]; } } return(commandOutput.ToString()); }
public void TestNegativeValues() { var intcode = new Intcode("1101,100,-1,4,0"); intcode.Process(); Assert.Equal(1101, intcode.Result); Assert.Equal(99, intcode.ReadMemory(0)); }
public void SolvePart1() { var intcode = new Intcode(); int exitCode = intcode.Run(airConSystemId, "../../../input/day_05.txt"); Assert.Equal(0, exitCode); Assert.Equal(10987514, intcode.Diagnostics.Peek()); }
public OxygenSystemLocater() { _repairDroid = Intcode.LoadFromFile("Day15/RepairDroid.txt"); _repairDroidInput = new IOPipe(); _repairDroidOutput = new IOPipe(); _repairDroid.SetInput(_repairDroidInput); _repairDroid.SetOutput(_repairDroidOutput); _map = new Map(); }
public string SolveA() { var lines = File.ReadAllLines(Input, Encoding.UTF8); var program = Intcode.ParseInput(lines[0]); var state = new Intcode.State(program); var found = FindIt(state, new List <Movement>()); return(found.Count.ToString()); }
private IntType[] RunProgram(IntType[] program) { var state = new Intcode.State(program); while (Intcode.Step(state)) { // nothing } return(state.MemoryDump(program.Length)); }