Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. It's Primes as far as the eye can see!

It's Primes as far as the eye can see!

Scheduled Pinned Locked Moved The Weird and The Wonderful
question
44 Posts 12 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • OriginalGriffO OriginalGriff

    This is the whole of a would-be Tip submitted today:

    public class Class1
    {
    static void Main(string[] args)
    {
    Console.WriteLine("Enter a Number");
    int num = int.Parse(Console.ReadLine());
    for (int i = 1; i <=num ; i++)
    {
    if(i==2)
    Console.WriteLine(2);

                if (i % 2 != 0)
                {
                    Console.WriteLine(i);
                }
            }
    
         }
    }
    

    No text, no explanation - the author (I can only assume he works for Mindfire, it's about their level) clearly felt that it spoke for itself. And boy, does it ever! This, ladies-n-gentlemen, is a Prime Number generator according to the author. So...I tried it... According to this code, the prime numbers under 26 are:

    1
    2
    3
    5
    7
    9
    11
    13
    15
    17
    19
    21
    23
    25

    Now, call me old fashioned, but in my day, 9, 15 and 21 were divisible by 3, and both 15 and 25 were divisible by 5... So which is wrong? The Code? Or the Laws of Mathematics? Only the author can tell... :laugh:

    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

    I Offline
    I Offline
    Ian Shlasko
    wrote on last edited by
    #3

    You know, as someone who's been messing around in Project Euler lately and could now code a Sieve of Eratosthenes* in his sleep, that algorithm makes me cry a little inside. (You know, it's easier to code the algorithm than to spell that guy's name...)

    Proud to have finally moved to the A-Ark. Which one are you in?
    Author of the Guardians Saga (Sci-Fi/Fantasy novels)

    1 Reply Last reply
    0
    • Z ZurdoDev

      OriginalGriff wrote:

      call me old fashioned, but in my day, 9, 15 and 21 were divisible by 3

      Ya, but that's also back when Pluto was a planet. We live in a very different place now. This user submitted this in QA, got closed, and resubmitted it in QA. I told him to post as a tip but apparently he didn't realize some explanation should be added. Or, the important part, THAT IT SHOULD WORK! :laugh:

      There are only 10 types of people in the world, those who understand binary and those who don't.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #4

      RyanDev wrote:

      back when Pluto was a planet.

      What? You mean he wasn't always a dog? :omg:

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        This is the whole of a would-be Tip submitted today:

        public class Class1
        {
        static void Main(string[] args)
        {
        Console.WriteLine("Enter a Number");
        int num = int.Parse(Console.ReadLine());
        for (int i = 1; i <=num ; i++)
        {
        if(i==2)
        Console.WriteLine(2);

                    if (i % 2 != 0)
                    {
                        Console.WriteLine(i);
                    }
                }
        
             }
        }
        

        No text, no explanation - the author (I can only assume he works for Mindfire, it's about their level) clearly felt that it spoke for itself. And boy, does it ever! This, ladies-n-gentlemen, is a Prime Number generator according to the author. So...I tried it... According to this code, the prime numbers under 26 are:

        1
        2
        3
        5
        7
        9
        11
        13
        15
        17
        19
        21
        23
        25

        Now, call me old fashioned, but in my day, 9, 15 and 21 were divisible by 3, and both 15 and 25 were divisible by 5... So which is wrong? The Code? Or the Laws of Mathematics? Only the author can tell... :laugh:

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

        N Offline
        N Offline
        newton saber
        wrote on last edited by
        #5

        All odd numbers are prime, right? Let me check. Yep, all odd numbers are prime. Makes it a lot easier to count by the primes. Also, are there more odd numbers or even numbers? I know the answer, but it's a puzzle for you.

        I OriginalGriffO P 3 Replies Last reply
        0
        • N newton saber

          All odd numbers are prime, right? Let me check. Yep, all odd numbers are prime. Makes it a lot easier to count by the primes. Also, are there more odd numbers or even numbers? I know the answer, but it's a puzzle for you.

          I Offline
          I Offline
          Ian Shlasko
          wrote on last edited by
          #6

          newton.saber wrote:

          Also, are there more odd numbers or even numbers? I know the answer, but it's a puzzle for you.

          I dunno, let's find out... You start naming odd numbers, and I'll start naming even numbers... Whoever can name more of them wins! :laugh: By the way, is Infinity odd or even? I mean, it's a sideways 8, and 8 is even... But since it's sideways, that's a little odd, right? It's also kind of a car, except they spell it oddly, so maybe the original spelling is even... My head hurts...

          Proud to have finally moved to the A-Ark. Which one are you in?
          Author of the Guardians Saga (Sci-Fi/Fantasy novels)

          D 1 Reply Last reply
          0
          • N newton saber

            All odd numbers are prime, right? Let me check. Yep, all odd numbers are prime. Makes it a lot easier to count by the primes. Also, are there more odd numbers or even numbers? I know the answer, but it's a puzzle for you.

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #7

            newton.saber wrote:

            it's a puzzle for you.

            Not really: there are an infinite quantity of each. The way we define "more", "less", and "equal" for infinite quantities is as follows. For two collections A and B (say A are the even numbers and B are the odd numbers) we say that If you can associate every item in A with a unique item in B, and vice versa, then A and B are the same size. If you can associate every item in A with a unique item in B, but not vice versa, then B is bigger than A. If you can associate every item in B with a unique item in A, but not vice versa, then A is bigger than B. In this case you can associate every even number n with the odd number n+1, and you can associate every odd number m with the even number m−1 (assuming 0 is even) so therefore there are just as many odd numbers as even numbers.

            Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            N 1 Reply Last reply
            0
            • I Ian Shlasko

              newton.saber wrote:

              Also, are there more odd numbers or even numbers? I know the answer, but it's a puzzle for you.

              I dunno, let's find out... You start naming odd numbers, and I'll start naming even numbers... Whoever can name more of them wins! :laugh: By the way, is Infinity odd or even? I mean, it's a sideways 8, and 8 is even... But since it's sideways, that's a little odd, right? It's also kind of a car, except they spell it oddly, so maybe the original spelling is even... My head hurts...

              Proud to have finally moved to the A-Ark. Which one are you in?
              Author of the Guardians Saga (Sci-Fi/Fantasy novels)

              D Offline
              D Offline
              den2k88
              wrote on last edited by
              #8

              Quote:

              By the way, is Infinity odd or even? I mean, it's a sideways 8, and 8 is even... But since it's sideways, that's a little odd, right?

              Please, stop! You're hurting me! :-D

              1 Reply Last reply
              0
              • N newton saber

                All odd numbers are prime, right? Let me check. Yep, all odd numbers are prime. Makes it a lot easier to count by the primes. Also, are there more odd numbers or even numbers? I know the answer, but it's a puzzle for you.

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #9

                newton.saber wrote:

                All odd numbers are prime, right?

                No, primes aren't just any odd number.

                N 1 Reply Last reply
                0
                • Z ZurdoDev

                  OriginalGriff wrote:

                  call me old fashioned, but in my day, 9, 15 and 21 were divisible by 3

                  Ya, but that's also back when Pluto was a planet. We live in a very different place now. This user submitted this in QA, got closed, and resubmitted it in QA. I told him to post as a tip but apparently he didn't realize some explanation should be added. Or, the important part, THAT IT SHOULD WORK! :laugh:

                  There are only 10 types of people in the world, those who understand binary and those who don't.

                  D Offline
                  D Offline
                  DaveAuld
                  wrote on last edited by
                  #10

                  RyanDev wrote:

                  but that's also back when Pluto was a planet

                  There was a thing on the telly recently that stated it had been voted back in as a planet.

                  Dave Find Me On:Web|Facebook|Twitter|LinkedIn Folding Stats: Team CodeProject

                  Z P N 3 Replies Last reply
                  0
                  • D DaveAuld

                    RyanDev wrote:

                    but that's also back when Pluto was a planet

                    There was a thing on the telly recently that stated it had been voted back in as a planet.

                    Dave Find Me On:Web|Facebook|Twitter|LinkedIn Folding Stats: Team CodeProject

                    Z Offline
                    Z Offline
                    ZurdoDev
                    wrote on last edited by
                    #11

                    True fans never gave up hope. :thumbsup::thumbsup:

                    There are only 10 types of people in the world, those who understand binary and those who don't.

                    1 Reply Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      This is the whole of a would-be Tip submitted today:

                      public class Class1
                      {
                      static void Main(string[] args)
                      {
                      Console.WriteLine("Enter a Number");
                      int num = int.Parse(Console.ReadLine());
                      for (int i = 1; i <=num ; i++)
                      {
                      if(i==2)
                      Console.WriteLine(2);

                                  if (i % 2 != 0)
                                  {
                                      Console.WriteLine(i);
                                  }
                              }
                      
                           }
                      }
                      

                      No text, no explanation - the author (I can only assume he works for Mindfire, it's about their level) clearly felt that it spoke for itself. And boy, does it ever! This, ladies-n-gentlemen, is a Prime Number generator according to the author. So...I tried it... According to this code, the prime numbers under 26 are:

                      1
                      2
                      3
                      5
                      7
                      9
                      11
                      13
                      15
                      17
                      19
                      21
                      23
                      25

                      Now, call me old fashioned, but in my day, 9, 15 and 21 were divisible by 3, and both 15 and 25 were divisible by 5... So which is wrong? The Code? Or the Laws of Mathematics? Only the author can tell... :laugh:

                      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #12

                      At least he used the % operator rather than implementing his own function.

                      OriginalGriffO I 2 Replies Last reply
                      0
                      • P PIEBALDconsult

                        At least he used the % operator rather than implementing his own function.

                        OriginalGriffO Offline
                        OriginalGriffO Offline
                        OriginalGriff
                        wrote on last edited by
                        #13

                        I suspect luck was involved.

                        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                        1 Reply Last reply
                        0
                        • P PIEBALDconsult

                          At least he used the % operator rather than implementing his own function.

                          I Offline
                          I Offline
                          Ian Shlasko
                          wrote on last edited by
                          #14

                          Yeah, it could have been worse...

                          public static bool SeeIfNumberIsOdd(int i)
                          {
                          for (int n = i; n > 0; n--)
                          {
                          if (n==1)
                          return true;
                          else if (n==2)
                          return false;
                          }
                          return true;
                          }

                          That felt dirty to write... Ok, I probably could have made it a LITTLE worse... Maybe O(n^2), but that might be gratuitous.

                          Proud to have finally moved to the A-Ark. Which one are you in?
                          Author of the Guardians Saga (Sci-Fi/Fantasy novels)

                          P 1 Reply Last reply
                          0
                          • I Ian Shlasko

                            Yeah, it could have been worse...

                            public static bool SeeIfNumberIsOdd(int i)
                            {
                            for (int n = i; n > 0; n--)
                            {
                            if (n==1)
                            return true;
                            else if (n==2)
                            return false;
                            }
                            return true;
                            }

                            That felt dirty to write... Ok, I probably could have made it a LITTLE worse... Maybe O(n^2), but that might be gratuitous.

                            Proud to have finally moved to the A-Ark. Which one are you in?
                            Author of the Guardians Saga (Sci-Fi/Fantasy novels)

                            P Offline
                            P Offline
                            PIEBALDconsult
                            wrote on last edited by
                            #15

                            See the mod function in here: http://www.codeproject.com/script/Articles/ArticleVersion.aspx?aid=830657[^]

                            I 1 Reply Last reply
                            0
                            • P PIEBALDconsult

                              See the mod function in here: http://www.codeproject.com/script/Articles/ArticleVersion.aspx?aid=830657[^]

                              I Offline
                              I Offline
                              Ian Shlasko
                              wrote on last edited by
                              #16

                              Bah, I can do better than that!

                              //TODO: Remove all comments before publishing. Real programmers don't need comments!
                              public function SuperMod(int n, int o) // o is a great variable, because it looks like a zero
                              {
                              int p = o; //Shorter variable names make the code run faster!
                              loopy: //Labels make me feel young again!
                              while (p < n) p += o;
                              if (p < n) goto loopy; //Just in case the compiler makes a mistake
                              int answer = p - n;
                              return answer;
                              }

                              Ok, I think that's about as bad as I can make it, and though I didn't test it at all (Honestly, I think the compiler would come to life and slit my throat for even trying to execute this monstrosity), that should technically give the right answer... Unless 'o' is negative or zero, but validating parameters is so 20th century...

                              Proud to have finally moved to the A-Ark. Which one are you in?
                              Author of the Guardians Saga (Sci-Fi/Fantasy novels)

                              P B 2 Replies Last reply
                              0
                              • I Ian Shlasko

                                Bah, I can do better than that!

                                //TODO: Remove all comments before publishing. Real programmers don't need comments!
                                public function SuperMod(int n, int o) // o is a great variable, because it looks like a zero
                                {
                                int p = o; //Shorter variable names make the code run faster!
                                loopy: //Labels make me feel young again!
                                while (p < n) p += o;
                                if (p < n) goto loopy; //Just in case the compiler makes a mistake
                                int answer = p - n;
                                return answer;
                                }

                                Ok, I think that's about as bad as I can make it, and though I didn't test it at all (Honestly, I think the compiler would come to life and slit my throat for even trying to execute this monstrosity), that should technically give the right answer... Unless 'o' is negative or zero, but validating parameters is so 20th century...

                                Proud to have finally moved to the A-Ark. Which one are you in?
                                Author of the Guardians Saga (Sci-Fi/Fantasy novels)

                                P Offline
                                P Offline
                                PIEBALDconsult
                                wrote on last edited by
                                #17

                                Ian Shlasko wrote:

                                give the right an answer

                                FTFY

                                I 1 Reply Last reply
                                0
                                • P PIEBALDconsult

                                  newton.saber wrote:

                                  All odd numbers are prime, right?

                                  No, primes aren't just any odd number.

                                  N Offline
                                  N Offline
                                  newton saber
                                  wrote on last edited by
                                  #18

                                  PIEBALDconsult wrote:

                                  No, primes aren't just any odd number.

                                  Of course they are. It's ridiculous to think that they aren't.

                                  1 Reply Last reply
                                  0
                                  • OriginalGriffO OriginalGriff

                                    newton.saber wrote:

                                    it's a puzzle for you.

                                    Not really: there are an infinite quantity of each. The way we define "more", "less", and "equal" for infinite quantities is as follows. For two collections A and B (say A are the even numbers and B are the odd numbers) we say that If you can associate every item in A with a unique item in B, and vice versa, then A and B are the same size. If you can associate every item in A with a unique item in B, but not vice versa, then B is bigger than A. If you can associate every item in B with a unique item in A, but not vice versa, then A is bigger than B. In this case you can associate every even number n with the odd number n+1, and you can associate every odd number m with the even number m−1 (assuming 0 is even) so therefore there are just as many odd numbers as even numbers.

                                    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                                    N Offline
                                    N Offline
                                    newton saber
                                    wrote on last edited by
                                    #19

                                    This is terribly incorrect, because I stopped counting on an odd number, so there are more odd numbers than even. Thank you for your input. :D

                                    P 1 Reply Last reply
                                    0
                                    • OriginalGriffO OriginalGriff

                                      This is the whole of a would-be Tip submitted today:

                                      public class Class1
                                      {
                                      static void Main(string[] args)
                                      {
                                      Console.WriteLine("Enter a Number");
                                      int num = int.Parse(Console.ReadLine());
                                      for (int i = 1; i <=num ; i++)
                                      {
                                      if(i==2)
                                      Console.WriteLine(2);

                                                  if (i % 2 != 0)
                                                  {
                                                      Console.WriteLine(i);
                                                  }
                                              }
                                      
                                           }
                                      }
                                      

                                      No text, no explanation - the author (I can only assume he works for Mindfire, it's about their level) clearly felt that it spoke for itself. And boy, does it ever! This, ladies-n-gentlemen, is a Prime Number generator according to the author. So...I tried it... According to this code, the prime numbers under 26 are:

                                      1
                                      2
                                      3
                                      5
                                      7
                                      9
                                      11
                                      13
                                      15
                                      17
                                      19
                                      21
                                      23
                                      25

                                      Now, call me old fashioned, but in my day, 9, 15 and 21 were divisible by 3, and both 15 and 25 were divisible by 5... So which is wrong? The Code? Or the Laws of Mathematics? Only the author can tell... :laugh:

                                      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                                      P Offline
                                      P Offline
                                      PIEBALDconsult
                                      wrote on last edited by
                                      #20

                                      http://www.codeproject.com/Lounge.aspx?msg=85311#xx85311xx[^] http://www.codeproject.com/search.aspx?q=prime+number+error&categoryid=f1_1159_[^]

                                      1 Reply Last reply
                                      0
                                      • OriginalGriffO OriginalGriff

                                        This is the whole of a would-be Tip submitted today:

                                        public class Class1
                                        {
                                        static void Main(string[] args)
                                        {
                                        Console.WriteLine("Enter a Number");
                                        int num = int.Parse(Console.ReadLine());
                                        for (int i = 1; i <=num ; i++)
                                        {
                                        if(i==2)
                                        Console.WriteLine(2);

                                                    if (i % 2 != 0)
                                                    {
                                                        Console.WriteLine(i);
                                                    }
                                                }
                                        
                                             }
                                        }
                                        

                                        No text, no explanation - the author (I can only assume he works for Mindfire, it's about their level) clearly felt that it spoke for itself. And boy, does it ever! This, ladies-n-gentlemen, is a Prime Number generator according to the author. So...I tried it... According to this code, the prime numbers under 26 are:

                                        1
                                        2
                                        3
                                        5
                                        7
                                        9
                                        11
                                        13
                                        15
                                        17
                                        19
                                        21
                                        23
                                        25

                                        Now, call me old fashioned, but in my day, 9, 15 and 21 were divisible by 3, and both 15 and 25 were divisible by 5... So which is wrong? The Code? Or the Laws of Mathematics? Only the author can tell... :laugh:

                                        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                                        P Offline
                                        P Offline
                                        PhilLenoir
                                        wrote on last edited by
                                        #21

                                        That's odd!

                                        Life is like a s**t sandwich; the more bread you have, the less s**t you eat.

                                        1 Reply Last reply
                                        0
                                        • D DaveAuld

                                          RyanDev wrote:

                                          but that's also back when Pluto was a planet

                                          There was a thing on the telly recently that stated it had been voted back in as a planet.

                                          Dave Find Me On:Web|Facebook|Twitter|LinkedIn Folding Stats: Team CodeProject

                                          P Offline
                                          P Offline
                                          PhilLenoir
                                          wrote on last edited by
                                          #22

                                          That's democracy for you!

                                          Life is like a s**t sandwich; the more bread you have, the less s**t you eat.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups