public static void ExempleSpiral()
        {
            UlamSpiral spiral = new UlamSpiral(189);

            System.Diagnostics.Stopwatch watch;

            //
            watch = System.Diagnostics.Stopwatch.StartNew();
            for (int i = 0; i <= spiral.MaxCycle; i++)
            {
                spiral.Cycle(i);
            }
            watch.Stop();
            Console.WriteLine("{0} ticks pour les cycles", watch.ElapsedTicks);
            /**/

            watch = System.Diagnostics.Stopwatch.StartNew();
            int distance = spiral.Resolve();

            watch.Stop();


            Console.WriteLine("{0} ticks pour la résolution", watch.ElapsedTicks);
            Console.WriteLine("{0} est à une distance de {1} du centre.", spiral.TargetValue, distance);
            Console.WriteLine(spiral);
        }
Example #2
0
        public void TestUlamSpiralCycleOK()
        {
            UlamSpiral spiral = null;

            int[] loc         = null;
            int   cycleNumber = 0;

            spiral      = new UlamSpiral(25);
            cycleNumber = 1;
            spiral.Cycle(cycleNumber);
            loc = spiral.GetStartLocation(cycleNumber);
            Assert.AreEqual(2, spiral.Matrix[loc[1], loc[0]]);

            spiral      = new UlamSpiral(25);
            cycleNumber = 2;
            spiral.Cycle(cycleNumber);
            loc = spiral.GetStartLocation(cycleNumber);
            Assert.AreEqual(10, spiral.Matrix[loc[1], loc[0]]);

            spiral      = new UlamSpiral(49);
            cycleNumber = 3;
            spiral.Cycle(cycleNumber);
            loc = spiral.GetStartLocation(cycleNumber);
            Assert.AreEqual(26, spiral.Matrix[loc[1], loc[0]]);
        }