Exemplo n.º 1
0
        static int GetPeriod(string program, Func <Moon, string> selector)
        {
            var system = new JupiterSystem(program);

/*@"<x=-1, y=0, z=2>
 * <x=2, y=-10, z=-7>
 * <x=4, y=-8, z=8>
 * <x=3, y=5, z=-1>");           */
/*            var system=new JupiterSystem(@"<x=-8, y=-10, z=0>
 * <x=5, y=5, z=10>
 * <x=2, y=-7, z=3>
 * <x=9, y=-8, z=-3>");*/

/*            var system=new JupiterSystem(@"<x=0, y=6, z=1>
 * <x=4, y=4, z=19>
 * <x=-11, y=1, z=8>
 * <x=2, y=19, z=15>");*/

            byte[] initHash = system.GetUniverseHash(selector);
            //Console.WriteLine(system.Moons[0]);
            int i = 0;

            while (true)
            {
                system.SimulateTimeStep();
                //Console.WriteLine(system.Moons[0]);
                var hash = system.GetUniverseHash(selector);
                if (initHash.SequenceEqual(hash))
                {
                    Console.WriteLine($"Old Pos ! {i} { system.Moons[0].ToString() }");
                    return(i + 1);
                }
                i++;
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string program = @"<x=0, y=6, z=1>
<x=4, y=4, z=19>
<x=-11, y=1, z=8>
<x=2, y=19, z=15>";
            var    system  = new JupiterSystem(program);

            system.SimulateTimeStep(1000);
            Console.WriteLine($"Energy = {system.GetTotalEnergy()}");

            Console.WriteLine("=> X");
            var periodX = GetPeriod(program, x => x.X + " " + x.vX); //+" "+x.Y+" "+x.vY+" "+x.Z+" "+x.vZ);

            Console.WriteLine("=> Y");
            var periodY = GetPeriod(program, x => x.Y + " " + x.vY);

            Console.WriteLine("=> Z");
            var periodZ = GetPeriod(program, x => x.Z + " " + x.vZ);

            Console.WriteLine($"GlobalPeriod {LCM(periodX,periodY,periodZ)}");
        }