Prime Numbers

2»

Comments

  • CronosCronos Join Date: 2002-10-18 Member: 1542Members
    edited January 2004
    Nice Job punching a hole there confuzor, I've found that if you multiply by other primes in those cases you can get further primes.

    Example

    41 * 7 = 287

    287 - 2 = 285 -> Not Prime
    287 + 2 = 289 -> {EDIT} Upon Further Research, this number is not a prime, so although the above statement is somewhat correct, this example is a very bad case in point.

    The problem with multiplying using higher primes is that they are less and less reliable.

    Although not a definitive theory it could point to something more. So far the only exception appears to be 41, I'd be happy if people could point out any to me.

    Any good theory needs refinement and a theory for primes has so far never been devised.
  • Soylent_greenSoylent_green Join Date: 2002-12-20 Member: 11220Members, Reinforced - Shadow
    edited January 2004
    I made a little proggie(I need the practice).

    Feel free to play with it if you wan't to try any new ideas. 31 is the first prime for which it fails.

    <!--QuoteBegin--></span><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> </td></tr><tr><td id='QUOTE'><!--QuoteEBegin-->//-------------------------------------------------------------------------------------------------
    //DEFINES
    //-------------------------------------------------------------------------------------------------
    //instructs compiler through header file logic not to include MFC stuff
    #define WIN32_LEAN_AND_MEAN

    //program states
    #define STATE_INIT 1
    #define STATE_RUN 2
    #define STATE_QUIT 3
    #define STATE_EXCEPTIONFOUND 4
    #define STATE_ERROR 5
    #define STATE_NOEXCEPTIONFOUND 6
    //-------------------------------------------------------------------------------------------------
    //INCLUDES
    //-------------------------------------------------------------------------------------------------
    #include <windows.h>
    //Not needed for this stuff #include <windowsx.h>
    #include <math.h> //sqrt
    #include <stdlib.h> //ltoa
    #include <string.h> //strcat
    //-------------------------------------------------------------------------------------------------
    //GLOBALS
    //-------------------------------------------------------------------------------------------------
    int state=STATE_INIT;
    int error=0;

    //only test this far
    const unsigned long limit=1000;
    //-------------------------------------------------------------------------------------------------
    //FUNCTION DECLARATIONS
    //-------------------------------------------------------------------------------------------------
    bool IsPrime(unsigned long n); //returns true (i.e. 1) if prime, false (i.e. 0) if not
    //-------------------------------------------------------------------------------------------------
    //WINMAIN
    //-------------------------------------------------------------------------------------------------

    int WINAPI WinMain(HINSTANCE hInstance,
           HINSTANCE hPrevInstance,
           LPSTR lpcmdline,
           int nCMDShow)
    {
    //the number currently being tested
    unsigned long CurrentNumber=1;

    //main event loop
    while(state!=STATE_QUIT)
    {
      switch (state)
      {
      case STATE_INIT:
       {
        //do initialization of stuff here if needed
      
        //set state to run
        state=STATE_RUN;
       } break; 
      case STATE_RUN:
       {
        //for performance reasons, do all testing without going through the switch
        while(state==STATE_RUN)
        {
         if(IsPrime(CurrentNumber))
         {
          bool temp[2];
          temp[0]=IsPrime(3*CurrentNumber+2);
          temp[1]=IsPrime(3*CurrentNumber-2);
         
          //if exception found, set state to exceptionfound
          if (!temp[0]&&!temp[1]) //if neither are true then both are false
          {
           state = STATE_EXCEPTIONFOUND;
           break; //quit the while statement without incrementing CurrentNumber by 2
          }
         } //end of if
         
         /*don't bother testing with even numbers, they are divisible by 2,
           2 is the only even prime number.
           this if statement adds a small overhead which is negligible compared
           to the time it takes to test if large numbers are prime*/
         if(CurrentNumber<=2)
         {
          CurrentNumber++;
         }
         else
         {
          CurrentNumber+=2;
         }
        
        
         /*if you run out of numbers smaller than the set limit to test,
           set the state to no exception found*/
         if(CurrentNumber>limit) state=STATE_NOEXCEPTIONFOUND;

        } //end of while
       } break;
      case STATE_EXCEPTIONFOUND:
       {
        //to output the first number for which the rule fails conversion to a string is needed
        char Current[11]; //a long contains 10 figures at most, 11 is needed for a null sign
        char Message[500]="\n"; //un-necessarily long, but I don't wan't buffer overflows
       
        //convert CurrentNumber to a number and stick it in the string Current
        ltoa(CurrentNumber,Current,10);
       
        //add the strings together back to back and put in Message
        strcat(Message,"OMG an exception was teh found!!!111\n\n");
        strcat(Message,"The prime ");
        strcat(Message,Current);
        strcat(Message," does not generate any new primes when multiplied by 3 and added to 2 or -2");

        //pop up a message box saying an exception was found
        MessageBox(
         NULL,
         Message,   
         "ah crap",
         MB_OK|MB_ICONEXCLAMATION);
     
        //play annoying beep noise
        MessageBeep(MB_ICONEXCLAMATION);

        //set state to quit
        state = STATE_QUIT;
       } break;
      case STATE_NOEXCEPTIONFOUND:
       {
        //pop up a message box saying no exception was found
        MessageBox(
         NULL,
         "no exception was found among the tested primes",
         "yay",
         MB_OK|MB_ICONEXCLAMATION);
     
        //play annoying beep noise
        MessageBeep(MB_ICONEXCLAMATION);

        //set state to quit
        state = STATE_QUIT;
       } break;
      case STATE_ERROR:
       {
        //pop up a message box saying an error was found
        MessageBox(
         NULL,
         "an error was encountered",
         "oh noes!!!11",
         MB_OK|MB_ICONSTOP);
       
        //play annoying beep noise
        MessageBeep(MB_ICONEXCLAMATION);

        //set state to quit
        state = STATE_QUIT;
       } break;
      case STATE_QUIT:
       {
       /*do cleanup if needed.
         program will exit the while-loop and quit*/
       } break;
      default: break;
      } //end of switch
    }//end of while
    return (error); //if error!=0 an error was encountered
    }

    //returns true if n is prime and false if not
    bool IsPrime(unsigned long n)
    {
    /*don't bother testing if integers above the squareroot are factors,
       if a number larger the square root is a factor then the other factor is smaller than the squareroot*/

    //explicit type casting to unsigned long chops of the decimals.
    unsigned long testlimit = (unsigned long)sqrt((double)n);

    //don't bother testing if 1 or 2 is factors
    unsigned long counter;

    /*test if any factors are found, don't bother finding even factors.
      A number divisible with an even number k, is also divisible by k/2.*/
    for (counter=3;counter<=testlimit;counter+=2)
    {
      //if n is evenly divisible with counter it is not prime, return false
      if(n%counter==0) return (false);
    } //end of for

    //if you get this far the number is not evenly divisible with any number but itself and 1
    return(true);
    }<!--QuoteEnd--></td></tr></table><span class='postcolor'><!--QuoteEEnd-->

    Gah... why are tabs shortened to 1 space? It makes it horrible to read...

    Grab it here if you want it instead of copy paste <a href='http://hem.bredband.net/congal/temp/prime.zip' target='_blank'>prime.zip</a>
  • DOOManiacDOOManiac Worst. Critic. Ever. Join Date: 2002-04-17 Member: 462Members, NS1 Playtester
    edited January 2004
    oops, disregard this, i'm dumb.
  • [WHO]Them[WHO]Them You can call me Dave Join Date: 2002-12-11 Member: 10593Members, Constellation
    <!--QuoteBegin--DOOManiac+Jan 4 2004, 10:51 PM--></span><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (DOOManiac @ Jan 4 2004, 10:51 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Allow me to conduct my own rigit mathmatical proof: <!--QuoteEnd--> </td></tr></table><span class='postcolor'> <!--QuoteEEnd-->
    can't argue with the facts.
  • DOOManiacDOOManiac Worst. Critic. Ever. Join Date: 2002-04-17 Member: 462Members, NS1 Playtester
    edited January 2004
    Allow me to conduct my own rigid mathmatical proof:
  • GadzukoGadzuko Join Date: 2002-12-26 Member: 11556Members, Constellation
    Hmmm, I think DOOM is on to something here. I say we submit this to some kind of mathematician's conference.
  • JimmehJimmeh Join Date: 2003-08-24 Member: 20173Members, Constellation
    I don't know if its already been said, but 1 is not a prime.

    While a prime number is a number that can only be divided exactly by 1 and itself, 1 is usually excluded from this definition.

    The reason is so that every positive integer greater than 1 can be expressed uniquely as a product of primes. For example, if we did allow 1 as a prime, then 6 = 2×3 = 1×2×3 = 1×1×2×3 etc. and uniqueness is lost.
  • AllUrHiveRblong2usAllUrHiveRblong2us By Your Powers Combined... Join Date: 2002-12-20 Member: 11244Members
    <!--QuoteBegin--Cronos+Jan 5 2004, 12:16 AM--></span><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Cronos @ Jan 5 2004, 12:16 AM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> 287 + 2 = 289 -> {EDIT} Upon Further Research, this number is not a prime <!--QuoteEnd--> </td></tr></table><span class='postcolor'> <!--QuoteEEnd-->
    For some reason, that made me almost fall out of my seat laughing. That has made my day, and it's not even 6:15 yet!
  • JimmehJimmeh Join Date: 2003-08-24 Member: 20173Members, Constellation
    <!--QuoteBegin--DOOManiac+Jan 5 2004, 06:56 AM--></span><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (DOOManiac @ Jan 5 2004, 06:56 AM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin-->Allow me to conduct my own rigit mathmatical proof:<!--QuoteEnd--></td></tr></table><span class='postcolor'><!--QuoteEEnd-->
    Transformer + Samus love?

    <!--emo&:0--><img src='http://www.unknownworlds.com/forums/html/emoticons/wow.gif' border='0' style='vertical-align:middle' alt='wow.gif'><!--endemo-->
  • tankefugltankefugl One Script To Rule Them All... Trondheim, Norway Join Date: 2002-11-14 Member: 8641Members, Retired Developer, NS1 Playtester, Constellation, NS2 Playtester, Squad Five Blue
    Ok, some small notes:

    Mathematical induction can indeed be used on primes, [WHO]Them.

    Mathematical induction is not the ONLY way to prove something (but it's actually the only way of proving something without the need of understanding why).

    Soylent green disproved the original theory by a counterexample. The original theory, however, was NOT proved -- it was just a couple of examples listed. Examples can not prove anything, but they can disprove.

    DOOManiac's teorem still stands, though. Makes perfect sense.
  • CronosCronos Join Date: 2002-10-18 Member: 1542Members
    There were bound to be holes but it is a fairly coherent pattern regardless.

    With a bit of work a proper pattern may be found.

    //raises imaginary wine glass

    To Pure Science, May it Be Of No Use To Anyone!
  • TequilaTequila Join Date: 2003-08-13 Member: 19660Members
    Maths smells. Metroid Prime rocks!
  • DOOManiacDOOManiac Worst. Critic. Ever. Join Date: 2002-04-17 Member: 462Members, NS1 Playtester
    "DOOManiac's Theorem"

    I like the sound of that! How do I apply for the mathmatical name patent or whatever it is!? :D
  • Nemesis_ZeroNemesis_Zero Old European Join Date: 2002-01-25 Member: 75Members, Retired Developer, NS1 Playtester, Constellation
    As far as I know, you and your supporters beat anyone of opposing opinion into submission. Maths are a harsh business.
  • Nil_IQNil_IQ Join Date: 2003-04-15 Member: 15520Members
    Shut up, all of you! I have math but I have to endure it to do cybernetics at uni! Aaarrgh!

    The good news is i'm going to pass P1.... this time. The bad news is im probaly going to flunk P2 big time.
  • DiablusDiablus Join Date: 2003-03-31 Member: 15080Members
    <!--QuoteBegin--Bosnian+Jan 4 2004, 11:33 PM--></span><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Bosnian @ Jan 4 2004, 11:33 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> I'm taking the second. I've failed all math subjects I've taken in high school at least once. But I somehow managed to get through and still stay only one year behind. <!--QuoteEnd--> </td></tr></table><span class='postcolor'> <!--QuoteEEnd-->
    hah, same here im in 2 too, i managed to get a 65 on my math 1 alg regents (well with the curve)

    Math sucks, i hate it, its brining my grades down and no matter how hard i try or how long i study i still fail 90% of my math tests... math just isnt for me
  • XiileXiile Join Date: 2003-02-22 Member: 13818Members
    <!--QuoteBegin--Diablus+Jan 4 2004, 10:18 PM--></span><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Diablus @ Jan 4 2004, 10:18 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> did u know <!--emo&::marine::--><img src='http://www.unknownworlds.com/forums/html/emoticons/marine.gif' border='0' style='vertical-align:middle' alt='marine.gif'><!--endemo--> + <!--emo&::marine::--><img src='http://www.unknownworlds.com/forums/html/emoticons/marine.gif' border='0' style='vertical-align:middle' alt='marine.gif'><!--endemo--> = <!--emo&::marine::--><img src='http://www.unknownworlds.com/forums/html/emoticons/marine.gif' border='0' style='vertical-align:middle' alt='marine.gif'><!--endemo--> <!--emo&::marine::--><img src='http://www.unknownworlds.com/forums/html/emoticons/marine.gif' border='0' style='vertical-align:middle' alt='marine.gif'><!--endemo--> ?!?!?!?! <!--QuoteEnd--> </td></tr></table><span class='postcolor'> <!--QuoteEEnd-->
    Yes, and:
    Let X = <!--emo&::marine::--><img src='http://www.unknownworlds.com/forums/html/emoticons/marine.gif' border='0' style='vertical-align:middle' alt='marine.gif'><!--endemo--> <!--emo&::marine::--><img src='http://www.unknownworlds.com/forums/html/emoticons/marine.gif' border='0' style='vertical-align:middle' alt='marine.gif'><!--endemo-->
    Let Y = <!--emo&::onos::--><img src='http://www.unknownworlds.com/forums/html/emoticons/tiny.gif' border='0' style='vertical-align:middle' alt='tiny.gif'><!--endemo-->
    X + Y = Y.

    Ok that didnt exactly make sense.
  • AllUrHiveRblong2usAllUrHiveRblong2us By Your Powers Combined... Join Date: 2002-12-20 Member: 11244Members
    If by "didn't exactly make sense" you meant "was most likely inspired by foreign substances interacting with brain matter" then yes.
Sign In or Register to comment.