public Day9() { var computer = new IntComputer(); computer.LoadProgram(FileUtils.LoadDataFor(9)).SetInput(() => 1).SetOutput((o) => _answer1 = o).Run(); computer.LoadProgram(FileUtils.LoadDataFor(9)).SetInput(() => 2).SetOutput((o) => _answer2 = o).Run(); }
public Day2() { var computer = new IntComputer(); _answer1 = computer.LoadProgram(FileUtils.LoadDataFor(2)).Using(12, 2).Run().MemoryZeroAddress; _answer2 = FindVerbAndNounForOutput(computer, 19690720); }
static void Main(string[] args) { IntComputer comp = new IntComputer(); string input = File.ReadAllText("IntComputerAircondition1.txt"); //string input = File.ReadAllText("IntComputerTests.txt"); string[] programs = input.Split('\n'); foreach (string p in programs) { comp.Print(comp.Parse(p)); comp.Run(p); } //foreach (string p in programs) //{ // Console.WriteLine(p); // for (int i = 0; i < 100; i++) // { // for (int j = 0; j < 100; j++) // { // try // { // var program = comp.Parse(p); // program[1] = i; // program[2] = j; // var result = comp.Run(program); // Console.WriteLine(i + " " + j + " " + result[0]); // if (result[0] == 19690720) // { // comp.Print(program); // return; // } // } // catch (Exception e) // { // // invalid input // } // } // } // Console.WriteLine(); //} Console.ReadLine(); }
private int FindVerbAndNounForOutput(IntComputer computer, int output) { for (var noun = 0; noun < 100; noun++) { for (var verb = 0; verb < 100; verb++) { if (computer .LoadProgram(FileUtils.LoadDataFor(2)) .Using(noun, verb) .Run() .MemoryZeroAddress == output) { return((100 * noun) + verb); } } } return(0); }