/// <inheritdoc /> public string Part1() { IntCodeVM2 vm = new IntCodeVM2(program); // show prompt vm.ExecuteProgram(); DrawASCIIOutput(vm.GetOutputs()); vm.ClearOutput(); // input program //J = (NOT A OR NOT B OR NOT C) AND D // // @ // ##ABCD### // // if D is ground and any of A,B,C aren't then jump ASCIIHelper helper = new ASCIIHelper(); helper.AddLine("NOT A T"); helper.AddLine("NOT B J"); helper.AddLine("OR T J"); helper.AddLine("NOT C T"); helper.AddLine("OR T J"); helper.AddLine("AND D J"); helper.AddLine("WALK"); vm.AddInput(helper.Convert()); // output what it showed vm.ResumeProgram(); if (vm.GetLastOutput() > 255) { Console.WriteLine($"\nhull damage taken: {vm.GetLastOutput()}"); } else { DrawASCIIOutput(vm.GetOutputs()); } return(""); }
/// <inheritdoc /> public string Part1() { // set to true to play the text adventure bool userPlay = false; IntCodeVM2 vm = new IntCodeVM2(program); vm.ExecuteProgram(); if (userPlay) { while (true) { // output foreach (long l in vm.GetOutputs()) { if (l < 255) { Console.Write((char)l); } else { Console.Write(l); } } vm.ClearOutput(); // input string inputLine = Console.ReadLine(); ASCIIHelper helper = new ASCIIHelper(); helper.AddLine(inputLine); vm.AddInput(helper.Convert()); vm.ResumeProgram(); } } else { // list of inputs to get to the end List <string> inputs = new List <string>() { "south", "take food ration", "west", "north", "north", "east", "take astrolabe", "west", "south", "south", "east", "north", "east", "south", "take weather machine", "west", "take ornament", "east", "north", "east", "east", "east", "south" }; ASCIIHelper helper = new ASCIIHelper(); foreach (string input in inputs) { helper.AddLine(input); } vm.AddInput(helper.Convert()); vm.ResumeProgram(); List <long> output = vm.GetOutputs(); output.RemoveAt(output.Count - 1); // remove last \n int lastLineStart = output.LastIndexOf(10); // get last sentence // convert characters to a string StringBuilder lastLine = new StringBuilder(); for (int i = lastLineStart + 1; i < output.Count; i++) { if (output[i] < 255) { lastLine.Append((char)output[i]); } else { lastLine.Append(output[i]); } } // get the number from the last line return(Regex.Match(lastLine.ToString(), @"\d+").Value); } return($""); }
/// <inheritdoc /> public string Part2() { IntCodeVM2 vm = new IntCodeVM2(program); // show prompt vm.ExecuteProgram(); DrawASCIIOutput(vm.GetOutputs()); vm.ClearOutput(); // input program // // @ // ##ABCDEFGHI### // // if D is ground and any of A,B,C aren't then jump (p1) // invert T (now equal to C) // if ((I OR F) AND E) OR H are ground, then jump ASCIIHelper helper = new ASCIIHelper(); helper.AddLine("NOT A T"); helper.AddLine("NOT B J"); helper.AddLine("OR T J"); helper.AddLine("NOT C T"); helper.AddLine("OR T J"); helper.AddLine("AND D J"); helper.AddLine("AND T T"); helper.AddLine("OR I T"); helper.AddLine("OR F T"); helper.AddLine("AND E T"); helper.AddLine("OR H T"); helper.AddLine("AND T J"); helper.AddLine("RUN"); vm.AddInput(helper.Convert()); // output what it showed vm.ResumeProgram(); if (vm.GetLastOutput() > 255) { Console.WriteLine($"\nhull damage taken: {vm.GetLastOutput()}"); } else { DrawASCIIOutput(vm.GetOutputs()); } return(""); }