Click here to Skip to main content
15,891,905 members
Home / Discussions / Algorithms
   

Algorithms

 
QuestionHow to get the index of a cell in a Table Pin
pix_programmer20-Dec-12 1:27
pix_programmer20-Dec-12 1:27 
AnswerRe: How to get the index of a cell in a Table Pin
Richard MacCutchan20-Dec-12 2:10
mveRichard MacCutchan20-Dec-12 2:10 
Questionconfusions Pin
en41117-Dec-12 22:37
en41117-Dec-12 22:37 
AnswerRe: confusions Pin
Alan Balkany18-Dec-12 5:43
Alan Balkany18-Dec-12 5:43 
QuestionWhen completing a bespoke programme should I give the code up? Pin
itorchuk17-Dec-12 8:08
itorchuk17-Dec-12 8:08 
AnswerRe: When completing a bespoke programme should I give the code up? Pin
jschell17-Dec-12 8:27
jschell17-Dec-12 8:27 
GeneralRe: When completing a bespoke programme should I give the code up? Pin
itorchuk17-Dec-12 8:37
itorchuk17-Dec-12 8:37 
QuestionPrime Number Generation Pin
Joshua Guyette14-Dec-12 9:36
Joshua Guyette14-Dec-12 9:36 
I first noticed this when I was in high school. But I can't seem to find any references to it on the Internet, did I discover something previously unknown?

I'm sure the algorithm can be made more efficient using other rules for generating prime numbers, but I'm just curious if anyone has even seen this before, and who (if not me), first discovered this.

How I'm generate prime numbers...

1. 2 is not include
2. Insert 3 and 5 into the prime number set
3. The next prime number is 7 = 5 + 3 - 1
4. The next prime number is 11 = 7 + 5 - 1
5. The next prime number is 13 = 11 + 3 - 1

So (Next Prime) = (Last Prime) + (Some Smaller Prime) - 1

Here is some C# code, showing this...
C#
void Test()
{
    List<long> primeNumbers = new List<long>();
    primeNumbers.Add(3);
    primeNumbers.Add(5);
    DateTime stopTime = DateTime.Now + new TimeSpan(0, 10, 0);
    Console.Write("Calculating prime numbers...");
    while (DateTime.Now < stopTime)
    {
        if (primeNumbers.Count % 100 == 0)
            Console.Write(".");
        primeNumbers.Add(GetNextPrime(primeNumbers));
    }
    Console.WriteLine("Calculated " + primeNumbers.Count + " prime numbers.");
    Console.WriteLine("The largest being " + primeNumbers.Last() + ".");
}

long GetNextPrime(List<long> primeNumbers)
{
    long lastPrime = primeNumbers.Last();
    for (int i = 0; i < primeNumbers.Count - 1; i++)
    {
        long testValue = lastPrime + primeNumbers[i] - 1;
        bool fail = false;
        for (int j = 0; j < primeNumbers.Count - 1; j++)
        {
            if (testValue % primeNumbers[j] == 0)
            {
                fail = true;
                break;
            }
        }
        if (fail) continue;
        return testValue;
    }
    throw new Exception("Rule failed");
}

AnswerRe: Prime Number Generation Pin
Alan Balkany17-Dec-12 4:39
Alan Balkany17-Dec-12 4:39 
AnswerRe: Prime Number Generation Pin
April Fans19-Dec-12 19:34
April Fans19-Dec-12 19:34 
AnswerRe: Prime Number Generation Pin
_Kel_30-Dec-12 4:44
_Kel_30-Dec-12 4:44 
QuestionFinding Bounding Entities Pin
Kyudos9-Dec-12 12:10
Kyudos9-Dec-12 12:10 
AnswerRe: Finding Bounding Entities Pin
Alan Balkany10-Dec-12 5:28
Alan Balkany10-Dec-12 5:28 
Questionneed a guidance Pin
en4114-Dec-12 22:08
en4114-Dec-12 22:08 
AnswerRe: need a guidance Pin
Alan Balkany5-Dec-12 4:55
Alan Balkany5-Dec-12 4:55 
AnswerRe: need a guidance Pin
Dr. Hurol Aslan1-Feb-13 3:55
Dr. Hurol Aslan1-Feb-13 3:55 
GeneralUSING PARTICLE SWARM OPTIMIZATION IN MATLAB Pin
李不凡 Dec20123-Dec-12 6:34
李不凡 Dec20123-Dec-12 6:34 
Questionalgorithms??? Pin
en4111-Dec-12 15:13
en4111-Dec-12 15:13 
AnswerRe: algorithms??? Pin
Peter_in_27801-Dec-12 19:34
professionalPeter_in_27801-Dec-12 19:34 
QuestionRe: algorithms??? Pin
April Fans27-Dec-12 4:17
April Fans27-Dec-12 4:17 
NewsWilling to Trade Ad Space on My site for work on my site Pin
Beyslist114-Nov-12 17:15
Beyslist114-Nov-12 17:15 
QuestionNeed a Classified Ad Aggregator Algorithm Pin
Beyslist114-Nov-12 17:14
Beyslist114-Nov-12 17:14 
Questionfinding the best algorithm Pin
speedchandu20-Oct-12 11:32
speedchandu20-Oct-12 11:32 
AnswerRe: finding the best algorithm Pin
Alan Balkany22-Oct-12 5:00
Alan Balkany22-Oct-12 5:00 
GeneralRe: finding the best algorithm Pin
speedchandu22-Oct-12 20:12
speedchandu22-Oct-12 20:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.