static Planet Copy(Planet planet) { return(new Planet(planet.location.X, planet.location.Y, planet.location.Z)); }
static private void Q2() { var workingPlanets = CopyPlanets(Inputs.planets); long iteration = 0; var originalState = CopyPlanets(workingPlanets); long xCycles = 0; long yCycles = 0; long zCycles = 0; do { //Update Vector foreach (var x in workingPlanets) { x.Update(workingPlanets.Where(y => y != x).ToList()); } //Move foreach (var x in workingPlanets) { x.Move(); } iteration++; //check x bool good = true; if (xCycles == 0) { for (int i = 0; i < workingPlanets.Count(); i++) { good = Planet.checkAxis(workingPlanets[i].location.X, originalState[i].location.X, workingPlanets[i].velocity.X, originalState[i].velocity.X); if (good == false) { break; } } if (good) { xCycles = iteration; } } if (yCycles == 0) { good = true; for (int i = 0; i < workingPlanets.Count(); i++) { good = Planet.checkAxis(workingPlanets[i].location.Y, originalState[i].location.Y, workingPlanets[i].velocity.Y, originalState[i].velocity.Y); if (good == false) { break; } } if (good) { yCycles = iteration; } } if (zCycles == 0) { good = true; for (int i = 0; i < workingPlanets.Count(); i++) { good = Planet.checkAxis(workingPlanets[i].location.Z, originalState[i].location.Z, workingPlanets[i].velocity.Z, originalState[i].velocity.Z); if (good == false) { break; } } if (good) { zCycles = iteration; } } } while (xCycles == 0 || yCycles == 0 || zCycles == 0); //Cheated a bit, used Wolfram Alpha to find the LCM Console.WriteLine($"Q2: {xCycles} {yCycles} {zCycles}"); }
public static bool Equivalent(Planet one, Planet two) { return(one.location.X == two.location.X && one.location.Y == two.location.Y && one.location.Z == two.location.Z); }