public void Day17_Puzzle1_FindX_OK() { var dictVoT = TrickShotProbe.FindValidVelocityXs(PuzzleTarget); Assert.NotEmpty(dictVoT); int actual = dictVoT.Values.Max(l => l.Max(t => t.Item2)); Assert.Equal(20, actual); }
public void Day17_Puzzle1_FindMaxY_OK() { var dictVoT = TrickShotProbe.FindValidVelocityYs(PuzzleTarget); // Look in the dictionary for highest max value. Assert.NotEmpty(dictVoT); int actual = dictVoT.Values.Max(l => l.Max(t => t.Item3)); int maxT = dictVoT.Values.Max(l => l.Max(t => t.Item2)); Assert.Equal(7381, actual); Assert.Equal(244, maxT); }
public void Day17_TestProbe_shots_OK(int vx, int vy, bool expected) { var target = TestTarget; var probe = new TrickShotProbe(vx, vy); bool inside = false; int count = 0; do { probe.DoSecond(); count++; inside = target.Inside(probe.X, probe.Y); if (inside) { break; } } while (probe.Y >= target.Y1); Assert.Equal(expected, inside); }
public void Day17_Puzzle2_OK() { var dictVelXs = TrickShotProbe.FindValidVelocityXs(PuzzleTarget); Assert.NotEmpty(dictVelXs); var dictVelYs = TrickShotProbe.FindValidVelocityYs(PuzzleTarget); Assert.NotEmpty(dictVelXs); Dictionary <Point, int> dictVels = new Dictionary <Point, int>(); var velXs = new List <Tuple <int, int, int> >(); foreach (var list in dictVelXs.Values) { velXs.AddRange(list); } // find VelX that stop in target. var stopVelx = velXs.Where(vx => vx.Item1 == vx.Item2).ToList(); Assert.Equal(2, stopVelx.Count); int minTxs = stopVelx.Min(t => t.Item2); var velYs = new List <Tuple <int, int, int> >(); foreach (var list in dictVelYs.Values) { velYs.AddRange(list); } var velYsOverMaxXTime = velYs.Where(vy => vy.Item2 >= minTxs); foreach (var vy in velYsOverMaxXTime) { foreach (var vx in stopVelx) { var p = new Point(vx.Item1, vy.Item1); if (!dictVels.ContainsKey(p)) { dictVels.Add(p, 1); } else { dictVels[p]++; } } } foreach (var vx in velXs) { foreach (var vy in velYs.Where(t => t.Item2 == vx.Item2)) { var p = new Point(vx.Item1, vy.Item1); if (!dictVels.ContainsKey(p)) { dictVels.Add(p, 1); } else { dictVels[p]++; } } } int actual = dictVels.Count; Assert.Equal(3019, actual); }