public override string Part1(string input) { var painted = new HashSet <Point>(); var point = new Point(0, 0); var direction = new Point(0, -1); var ic = new IntCode(input); try { while (true) { var color = white.Contains(point) ? 1 : 0; ic.SetInput(color); if (ic.RunToOutput() == 1) { white.Add(point); } else { white.Remove(point); } painted.Add(point); if (ic.RunToOutput() == 1) { direction = direction.RotateRight(); } else { direction = direction.RotateLeft(); } point = point.Plus(direction); } } catch (HaltException) { return(painted.Count().ToString()); } throw new InvalidOperationException(); }
public static void ExecuteStarTwo(string fileLocation = "PuzzleInput/Day2.txt") { string line = File.ReadAllText(fileLocation); bool outputFound = false; for (int currentNoun = 0; (currentNoun <= 99 && !outputFound); currentNoun++) { for (int currentVerb = 0; currentVerb <= 99 && !outputFound; currentVerb++) { IntCode intCode = new IntCode(Array.ConvertAll(line.Split(','), int.Parse), currentNoun, currentVerb); intCode.EvaluateCodes(); if (intCode.Memory[0] == 19690720) { Logger.LogMessage(LogLevel.ANSWER, "2B: Noun: " + currentNoun + "\t Verb: " + currentVerb + "\t Answer: " + (100 * currentNoun + currentVerb)); } } } }
public override string Part1(string input) { var ic = new IntCode(input); var blocks = 0; try { while (true) { ic.RunToOutput(); ic.RunToOutput(); if (ic.RunToOutput() == 2) { blocks++; } } } catch (HaltException) { return(blocks.ToString()); } }
public override string Part1(string input) { var ic = new IntCode(input); return(ic.Run(1).describe()); }
string testIC(string input) { var ic = new IntCode(input); return(ic.Run().describe()); }