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_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); }