public static uint CountTriangleSquares(long start, long end)
        {
            int count = 0;

            for (long j = start; j < end; j++)
            {
                long triangle = (j * (j + 1)) / 2;
                count += Optimized.CountIfSquareRotated(triangle);
            }
            return((uint)count);
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            uint      num        = 1000000;
            Stopwatch sw         = Stopwatch.StartNew();
            int       count      = 0;
            int       iterations = 100;

            for (int i = 0; i < iterations; i++)
            {
                //count = (int)Optimized.CountTriangleSquaresSinglethreaded(num);
                count = (int)Optimized.CountTriangleSquaresLinq(num);
                //count = (int)WithoutLinq.CountTriangleSquaresMultithreaded(num);
                //count = Naive.CountTriangleSquaresLinq(num);
            }
            var elapsed = sw.ElapsedMilliseconds;

            Console.WriteLine($"Av de første {num} triangeltall er {count} også kvadrater. (avg {elapsed / iterations} ms)");
        }