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.
  • P PIEBALDconsult

    Ian Shlasko wrote:

    give the right an answer

    FTFY

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

    Heh, yeah, you're right... It needs to be n+o-p... But hey, what's the point of testing when you're trying to write the worst code possible? (Still haven't tested... I was going to, but the compiler pulled a knife on me and said some very non-KSS things would happen if I tried)

    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
    • 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)

      B Offline
      B Offline
      Bert Mitton
      wrote on last edited by
      #24

      Cut and pasted ! :laugh:

      I 1 Reply Last reply
      0
      • B Bert Mitton

        Cut and pasted ! :laugh:

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

        Ok, but if you're gonna use that code, make sure to either fix the bug, or... uh... only test with (4,2).

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

        B 1 Reply Last reply
        0
        • N newton saber

          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 Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #26

          You might get a more accurate result if you start at infinity and count backward.

          N 1 Reply Last reply
          0
          • P PIEBALDconsult

            You might get a more accurate result if you start at infinity and count backward.

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

            PIEBALDconsult wrote:

            You might get a more accurate result if you start at infinity and count backward

            Great idea. I'm working on this now. :D

            OriginalGriffO 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

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

              DaveAuld wrote:

              it had been voted back in as a planet

              That is such a coincidence because I've just been voted in as a planet too. Very cool. I hope to be voted in as a Sun one day so I can go by the name Apollo. It's such a cool name. Plus then all you people will have to rotate around me and I'll be the center of your Universe. Yes, the sun is the center of the Universe. I pre-emptively struck on your future humor that I didn't know that the sun was the center of a solar system. Wham!

              D 1 Reply Last reply
              0
              • I Ian Shlasko

                Ok, but if you're gonna use that code, make sure to either fix the bug, or... uh... only test with (4,2).

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

                B Offline
                B Offline
                Bert Mitton
                wrote on last edited by
                #29

                Testing ? If it fails, that's what Q&A is for. I don't need to test. :-D

                1 Reply Last reply
                0
                • N newton saber

                  PIEBALDconsult wrote:

                  You might get a more accurate result if you start at infinity and count backward

                  Great idea. I'm working on this now. :D

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

                  Chuck Norris already did it. Twice.

                  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
                  • N newton saber

                    DaveAuld wrote:

                    it had been voted back in as a planet

                    That is such a coincidence because I've just been voted in as a planet too. Very cool. I hope to be voted in as a Sun one day so I can go by the name Apollo. It's such a cool name. Plus then all you people will have to rotate around me and I'll be the center of your Universe. Yes, the sun is the center of the Universe. I pre-emptively struck on your future humor that I didn't know that the sun was the center of a solar system. Wham!

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

                    back.....away.....from.....the.....keyboard......:~

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

                    I 1 Reply Last reply
                    0
                    • D DaveAuld

                      back.....away.....from.....the.....keyboard......:~

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

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

                      If he's the center of the universe, then technically shouldn't the keyboard back away from him?

                      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
                      • I Ian Shlasko

                        If he's the center of the universe, then technically shouldn't the keyboard back away from him?

                        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
                        DaveAuld
                        wrote on last edited by
                        #33

                        Maybe it can't because the gravitational pull is so strong.

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

                        I 1 Reply Last reply
                        0
                        • D DaveAuld

                          Maybe it can't because the gravitational pull is so strong.

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

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

                          Well, then it's time to invent an escape-assist rocket for a keyboard. Or honestly, maybe you should just let it collapse into him... If you add enough keyboards (And divert the entire manufacturing capacity of the human race to this for several million years), you could turn him into a black hole. I don't know where this is going, but my gut tells me it's just one punchline away from being funny.

                          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
                          • I Ian Shlasko

                            Well, then it's time to invent an escape-assist rocket for a keyboard. Or honestly, maybe you should just let it collapse into him... If you add enough keyboards (And divert the entire manufacturing capacity of the human race to this for several million years), you could turn him into a black hole. I don't know where this is going, but my gut tells me it's just one punchline away from being funny.

                            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
                            DaveAuld
                            wrote on last edited by
                            #35

                            Ian Shlasko wrote:

                            I don't know where this is going,

                            At the start I had visions of it heading towards Uranus.......

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

                            I N 3 Replies Last reply
                            0
                            • D DaveAuld

                              Ian Shlasko wrote:

                              I don't know where this is going,

                              At the start I had visions of it heading towards Uranus.......

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

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

                              DaveAuld wrote:

                              At the start I had visions of it heading towards Uranus.......

                              Ok, that's a start, but now you have to combine it with the semi-joke... Somehow connect that to a black h-- Ya know what... Let's just let that one go-- Err, no, don't do that... Uh... Just pass-- No...

                              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
                              • D DaveAuld

                                Ian Shlasko wrote:

                                I don't know where this is going,

                                At the start I had visions of it heading towards Uranus.......

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

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

                                Every time planets or orbits or space or universe or anything astronomical then there is the required mention of the 7th planet in our solar system. We really need a rename on that planet, don't you think?

                                I 1 Reply Last reply
                                0
                                • D DaveAuld

                                  Ian Shlasko wrote:

                                  I don't know where this is going,

                                  At the start I had visions of it heading towards Uranus.......

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

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

                                  This whole chain of riffs was great though. Way to go out there.

                                  1 Reply Last reply
                                  0
                                  • OriginalGriffO OriginalGriff

                                    Chuck Norris already did it. Twice.

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

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

                                    +2 for the chuck norris reference. I should've seen it coming, but I was busy with my countdown from infinity.

                                    1 Reply Last reply
                                    0
                                    • N newton saber

                                      Every time planets or orbits or space or universe or anything astronomical then there is the required mention of the 7th planet in our solar system. We really need a rename on that planet, don't you think?

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

                                      It was renamed... In 2620. Don't you watch Futurama?

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

                                      N 1 Reply Last reply
                                      0
                                      • I Ian Shlasko

                                        It was renamed... In 2620. Don't you watch Futurama?

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

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

                                        I haven't watched Futurama, because I boycotted The Simpsons in Season 2 and haven't watched anything by Matt Groening since. I know. Pretty cool, huh?

                                        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
                                          PaulLinton
                                          wrote on last edited by
                                          #42

                                          What's the problem? That lists all the primes less than 26. It also lists some other numbers as well, no extra charge.

                                          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