public long GetColor(General.clsPoint point) { long color; paintedPanels.TryGetValue(point, out color); return(color); }
public override string SolvePart2(string input = null) { string[] lines = input.Split(Environment.NewLine); List <General.clsPoint> Asteroids = new(); for (int i = 0; i < lines.Length; i++) { for (int j = 0; j < lines[i].Length; j++) { if (lines[i][j] == '#') { Asteroids.Add(new General.clsPoint(j, i)); } } } Dictionary <General.clsPoint, List <double> > PointAngles = new(); foreach (General.clsPoint pointA in Asteroids) { PointAngles[pointA] = new List <double>(); foreach (General.clsPoint pointB in Asteroids) { if (!pointA.Equals(pointB)) { PointAngles[pointA].Add(pointA.Angle(pointB)); } } PointAngles[pointA] = PointAngles[pointA].Distinct().ToList(); } General.clsPoint optimalPoint = PointAngles.Keys.OrderByDescending(x => PointAngles[x].Count).First(); List <General.clsPoint> Destroyed = new(); List <Tuple <double, double, General.clsPoint> > SortedAsteroids = orderAsteroids(optimalPoint, Asteroids); Double Angle = 0.0000000000000000001; while (SortedAsteroids.Count > 0) { Tuple <double, double, General.clsPoint> vaporized = SortedAsteroids.Where(x => x.Item1 < Angle).FirstOrDefault(); if (vaporized == null) { Angle = Math.PI * 2; } else { Angle = vaporized.Item1; Destroyed.Add(vaporized.Item3); SortedAsteroids.Remove(vaporized); } } return("" + (Destroyed[199].X * 100 + Destroyed[199].Y));; }
private void Move() { long color = GetColor(CurrentPosition); computer.InputValue(color); computer.ExecuteProgram(); paintedPanels[CurrentPosition] = computer.ReadOutputs()[0]; Rotate(computer.ReadOutputs()[1]); computer.ClearOutputs(); CurrentPosition = CurrentPosition.Move(direction); }
private List <Tuple <double, double, General.clsPoint> > orderAsteroids(General.clsPoint optimalPoint, List <General.clsPoint> Asteroids) { List <Tuple <double, double, General.clsPoint> > result = new(); foreach (General.clsPoint asteroid in Asteroids) { if (!asteroid.Equals(optimalPoint)) { result.Add(new Tuple <double, double, General.clsPoint>(asteroid.AnglePos(optimalPoint), asteroid.distance(optimalPoint), asteroid)); } } return(result.OrderByDescending(x => x.Item1).ThenBy(x => x.Item2).ToList()); }
public PaintingRobot(string sProgram, long start) { direction = General.Direction.Up; CurrentPosition = new General.clsPoint(0, 0); paintedPanels = new Dictionary <General.clsPoint, long>(); paintedPanels[CurrentPosition] = start; computer = new IntcodeComputer(); computer.loadProgram(sProgram); while (!computer.Halted) { Move(); } }
public List <General.clsPoint> PointsOnLine() { List <General.clsPoint> points = new(); General.clsPoint Huidig = start; int DeltaX = Math.Sign(end.X - start.X); int DeltaY = Math.Sign(end.Y - start.Y); while (!Huidig.Equals(end)) { points.Add(Huidig); Huidig = Huidig.plus(DeltaX, DeltaY); } points.Add(end); return(points); }
public Line(string rawData) { string[] points = rawData.Split(" -> "); start = new General.clsPoint(Double.Parse(points[0].Split(",")[0]), Double.Parse(points[0].Split(",")[1])); end = new General.clsPoint(Double.Parse(points[1].Split(",")[0]), Double.Parse(points[1].Split(",")[1])); }