/// <summary> /// The main method that is called outside this class that will solve the puzzle /// and return the answer /// </summary> /// <returns>The answer to the puzzle</returns> public int solvePuzzle() { // load the data from the PuzzleData.txt string puzzleData = this.LoadPuzzleDataIntoMemory(); // create an instance of compiler that will run the code Compiler.Compiler compiler = new Compiler.Compiler(); // covert the text file into a list of instcutions the compiler will understand compiler.parseInstructions(puzzleData); // run the program until completion or an invinat loop is dectected compiler.run(); // get the accumulator value which is the answer to the puzzle return(compiler.accumulatorValue); }
/// <summary> /// The main method that is called outside this class that will solve the puzzle /// and return the answer /// </summary> /// <returns>The answer to the puzzle</returns> public int solvePuzzle() { // load the data from the PuzzleData.txt string puzzleData = this.LoadPuzzleDataIntoMemory(); // create an instance of compiler that will run the code Compiler.Compiler compiler = new Compiler.Compiler(); // covert the text file into a list of instcutions the compiler will understand compiler.parseInstructions(puzzleData); // go through the instructions when we come accross a jump or no operation change // the code and then run it to see if the program executes correctly. // once we find a sequence where the code executes correctly, return that executions // acccumilators value as the answer to the puzzle int accumulatorValue = this.findCorrectCompilerSequence(compiler.ListOfInstructionsToRun); // the answer to part 2 of the puzzle return(accumulatorValue); }