Skip to main content
added 29 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

iI found an answer inon Stack Overflow a few days ago, i. I adapted it a bit to make it more parallel and easier to read.

--> i I might have made a mistake, mind me if i did. I I tested it in my computer. Core: Core i7 Second Gen (3Ghz3GHz). 12Gb with 12GB of ramRAM.

It took a few seconds to solve most of the numbers less than 50,000,000. However, it took around 6:32 seconds to solve 100,000,000. took It took around 47 mins to solve 500,000,000. and It crashed 11 hours after solving 1.5 billionsbillion.

MY CODE:

private static void GetPrimeNumbers(int max)
    {
        var allPossibleNumbers = Enumerable.Range(3, max-3);
        var possiblePrime = allPossibleNumbers
                .AsParallel()
                .Where(n => Enumerable.Range(2, (int)Math.Sqrt(n))
                                      .All(i => n % i != 0)
                )
                ;
        possiblePrime
                .ToArray()
                .AsParallel()
                .Dump()
                ;
    }

i found an answer in Stack Overflow a few days ago, i adapted it a bit to make it more parallel and easier to read.

--> i might have made a mistake, mind me if i did. I tested it in my computer. Core i7 Second Gen (3Ghz). 12Gb of ram.

took a few seconds to solve most of the numbers less than 50,000,000. However, took around 6:32 seconds to solve 100,000,000. took around 47 mins to solve 500,000,000. and crashed 11 hours after solving 1.5 billions.

MY CODE:

private static void GetPrimeNumbers(int max)
    {
        var allPossibleNumbers = Enumerable.Range(3, max-3);
        var possiblePrime = allPossibleNumbers
                .AsParallel()
                .Where(n => Enumerable.Range(2, (int)Math.Sqrt(n))
                                      .All(i => n % i != 0)
                )
                ;
        possiblePrime
                .ToArray()
                .AsParallel()
                .Dump()
                ;
    }

I found an answer on Stack Overflow a few days ago. I adapted it a bit to make it more parallel and easier to read.

I might have made a mistake. I tested it in my computer: Core i7 Second Gen (3GHz) with 12GB of RAM.

It took a few seconds to solve most of the numbers less than 50,000,000. However, it took around 6:32 seconds to solve 100,000,000. It took around 47 mins to solve 500,000,000. It crashed 11 hours after solving 1.5 billion.

private static void GetPrimeNumbers(int max)
{
    var allPossibleNumbers = Enumerable.Range(3, max-3);
    var possiblePrime = allPossibleNumbers
            .AsParallel()
            .Where(n => Enumerable.Range(2, (int)Math.Sqrt(n))
                                  .All(i => n % i != 0)
            )
            ;
    possiblePrime
            .ToArray()
            .AsParallel()
            .Dump()
            ;
}
Source Link

i found an answer in Stack Overflow a few days ago, i adapted it a bit to make it more parallel and easier to read.

--> i might have made a mistake, mind me if i did. I tested it in my computer. Core i7 Second Gen (3Ghz). 12Gb of ram.

took a few seconds to solve most of the numbers less than 50,000,000. However, took around 6:32 seconds to solve 100,000,000. took around 47 mins to solve 500,000,000. and crashed 11 hours after solving 1.5 billions.

MY CODE:

private static void GetPrimeNumbers(int max)
    {
        var allPossibleNumbers = Enumerable.Range(3, max-3);
        var possiblePrime = allPossibleNumbers
                .AsParallel()
                .Where(n => Enumerable.Range(2, (int)Math.Sqrt(n))
                                      .All(i => n % i != 0)
                )
                ;
        possiblePrime
                .ToArray()
                .AsParallel()
                .Dump()
                ;
    }