public void TestSimulate()
        {
            MotionSimulator ms = new MotionSimulator();

            Moon A = new Moon(-1, 0, 2);
            Moon B = new Moon(2, -10, -7);
            Moon C = new Moon(4, -8, 8);
            Moon D = new Moon(3, 5, -1);

            List <Moon> moons = new List <Moon>();

            moons.Add(A);
            moons.Add(B);
            moons.Add(C);
            moons.Add(D);

            ms.Simulate(moons, 10);

            Assert.That(A.PosX, Is.EqualTo(2));
            Assert.That(A.PosY, Is.EqualTo(1));
            Assert.That(A.PosZ, Is.EqualTo(-3));
            Assert.That(A.VelX, Is.EqualTo(-3));
            Assert.That(A.VelY, Is.EqualTo(-2));
            Assert.That(A.VelZ, Is.EqualTo(1));
        }
        public string SolvePartOne(string[] input, int steps)
        {
            MotionSimulator ms = new MotionSimulator();

            List <Moon> moons = ParseInput(input);

            ms.Simulate(moons, steps);

            return(ms.SystemEnergy(moons).ToString());
        }
        public void TestUpdatePosition()
        {
            MotionSimulator ms = new MotionSimulator();

            Moon A = new Moon(0, 0, 0);

            A.VelX = 1;
            A.VelY = 2;
            A.VelZ = 3;
            List <Moon> moons = new List <Moon>();

            moons.Add(A);

            ms.UpdatePosition(moons);

            Assert.That(A.VelX, Is.EqualTo(1));
            Assert.That(A.VelY, Is.EqualTo(2));
            Assert.That(A.VelZ, Is.EqualTo(3));
        }
        public void TestUpdateVelocity()
        {
            MotionSimulator ms = new MotionSimulator();

            Moon A = new Moon(0, 0, 0);
            Moon B = new Moon(1, 1, 1);

            List <Moon> moons = new List <Moon>(2);

            moons.Add(A);
            moons.Add(B);

            ms.UpdateVelocity(moons);

            Assert.That(A.VelX, Is.EqualTo(1));
            Assert.That(A.VelY, Is.EqualTo(1));
            Assert.That(A.VelZ, Is.EqualTo(1));
            Assert.That(B.VelX, Is.EqualTo(-1));
            Assert.That(B.VelY, Is.EqualTo(-1));
            Assert.That(B.VelZ, Is.EqualTo(-1));
        }
        public string SolvePartTwo(string[] input)
        {
            MotionSimulator ms = new MotionSimulator();

            List <Moon> moons        = ParseInput(input);
            List <Moon> initialState = ParseInput(input);

            long timelapseX = 0;
            long timelapseY = 0;
            long timelapseZ = 0;
            long step       = 0;

            do
            {
                ms.Step(moons);
                step++;

                if (IsInitialXState(moons, initialState) && timelapseX == 0)
                {
                    timelapseX = step;
                }

                if (IsInitialYState(moons, initialState) && timelapseY == 0)
                {
                    timelapseY = step;
                }

                if (IsInitialZState(moons, initialState) && timelapseZ == 0)
                {
                    timelapseZ = step;
                }
            } while(timelapseX == 0 || timelapseY == 0 || timelapseZ == 0);

            long steps = LCM(timelapseX, LCM(timelapseY, timelapseZ));

            return(steps.ToString());
        }