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. at least he tried

at least he tried

Scheduled Pinned Locked Moved The Weird and The Wonderful
question
42 Posts 25 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.
  • _ _anil_

    I really feel sorry for him... I hope u might not have scold that poor guy ;P

    Regards Anil

    E Offline
    E Offline
    Eric Georgiades
    wrote on last edited by
    #14

    Nah, since for most of their test data it returned good results.

    me, myself and my blog - loadx.org ericos g.

    1 Reply Last reply
    0
    • E Eric Georgiades

      as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :

      if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
      {
      return true;
      }
      else
      {
      return false;
      }

      when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?

      me, myself and my blog - loadx.org ericos g.

      S Offline
      S Offline
      Sylvester george
      wrote on last edited by
      #15

      He does not need any computer to find prime numbers :-D

      Regards, Sylvester G sylvester_g_m@yahoo.com

      1 Reply Last reply
      0
      • E Eric Georgiades

        as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :

        if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
        {
        return true;
        }
        else
        {
        return false;
        }

        when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?

        me, myself and my blog - loadx.org ericos g.

        R Offline
        R Offline
        Rage
        wrote on last edited by
        #16

        You are right, this is awful. Better is:

        int Primes[]={2,3,5,7,...,113};
        int size=sizeof(Primes[])/sizeof(Primes[0]);
        int i=0;
        while (i<size)
        {
        if (num==Primes[i]) return true;
        }
        return false;

        Last modified: 21hrs 3mins after originally posted --

        Constantly "Saving the day" should be taken as a sign of organizational dysfunction rather than individual skill - Ryan Roberts[^]

        P H B 3 Replies Last reply
        0
        • E Eric Georgiades

          as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :

          if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
          {
          return true;
          }
          else
          {
          return false;
          }

          when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?

          me, myself and my blog - loadx.org ericos g.

          N Offline
          N Offline
          Nemanja Trifunovic
          wrote on last edited by
          #17

          Beh, any real programmer would write it like this:

          int primes[] = {2,3,5,...133};
          const int* end = primes + sizeof(primes)/sizeof(int);
          return (std::find(primes, end, num) != end);


          Programming Blog utf8-cpp

          M P 2 Replies Last reply
          0
          • R Rage

            You are right, this is awful. Better is:

            int Primes[]={2,3,5,7,...,113};
            int size=sizeof(Primes[])/sizeof(Primes[0]);
            int i=0;
            while (i<size)
            {
            if (num==Primes[i]) return true;
            }
            return false;

            Last modified: 21hrs 3mins after originally posted --

            Constantly "Saving the day" should be taken as a sign of organizational dysfunction rather than individual skill - Ryan Roberts[^]

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

            I dunno, maybe a switch statement.

            1 Reply Last reply
            0
            • R Rage

              You are right, this is awful. Better is:

              int Primes[]={2,3,5,7,...,113};
              int size=sizeof(Primes[])/sizeof(Primes[0]);
              int i=0;
              while (i<size)
              {
              if (num==Primes[i]) return true;
              }
              return false;

              Last modified: 21hrs 3mins after originally posted --

              Constantly "Saving the day" should be taken as a sign of organizational dysfunction rather than individual skill - Ryan Roberts[^]

              H Offline
              H Offline
              hlmechanic
              wrote on last edited by
              #19

              Don't you just love infinate loops?:)

              P 1 Reply Last reply
              0
              • N Nemanja Trifunovic

                Beh, any real programmer would write it like this:

                int primes[] = {2,3,5,...133};
                const int* end = primes + sizeof(primes)/sizeof(int);
                return (std::find(primes, end, num) != end);


                Programming Blog utf8-cpp

                M Offline
                M Offline
                mav northwind
                wrote on last edited by
                #20

                And any real engineer would build something like this: :D

                bool IsPrime(int i)
                {
                if (i<2)
                return false;
                if (i == 2)
                return true;
                if (i%2 == 1)
                // All odd numbers are prime:
                // 3 ... prime
                // 5 ... prime
                // 7 ... prime
                // 9 ... measuring fault
                // 11... prime
                // 13... prime
                // and so on...
                return true;
                else
                return false;
                }

                Regards, mav -- Black holes are the places where God divided by 0...

                1 Reply Last reply
                0
                • E Eric Georgiades

                  as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :

                  if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
                  {
                  return true;
                  }
                  else
                  {
                  return false;
                  }

                  when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?

                  me, myself and my blog - loadx.org ericos g.

                  A Offline
                  A Offline
                  Andre Ladeira
                  wrote on last edited by
                  #21

                  The guy is hidden a genious! He calculated the prime numbers up to 113 without assistance! I would have stopped at 19... :-)

                  S 1 Reply Last reply
                  0
                  • H hlmechanic

                    Don't you just love infinate loops?:)

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

                    (Pssst, I think he used a <, but didn't remember to use < when he posted.) -- modified at 20:41 Thursday 14th June, 2007

                    int Primes[]={2,3,5,7,...,113};
                    int size=sizeof(Primes[])/sizeof(Primes[0]);
                    int i=0;
                    while (i<size)
                    {
                    if (num==Primes[i]) return true;
                    }
                    return false;

                    But you're right, it lacks i++.

                    S 1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      (Pssst, I think he used a <, but didn't remember to use < when he posted.) -- modified at 20:41 Thursday 14th June, 2007

                      int Primes[]={2,3,5,7,...,113};
                      int size=sizeof(Primes[])/sizeof(Primes[0]);
                      int i=0;
                      while (i<size)
                      {
                      if (num==Primes[i]) return true;
                      }
                      return false;

                      But you're right, it lacks i++.

                      S Offline
                      S Offline
                      Sylvester george
                      wrote on last edited by
                      #23

                      That is again Horror Coding :laugh:

                      Regards, Sylvester G sylvester_g_m@yahoo.com

                      L 1 Reply Last reply
                      0
                      • N Nemanja Trifunovic

                        Beh, any real programmer would write it like this:

                        int primes[] = {2,3,5,...133};
                        const int* end = primes + sizeof(primes)/sizeof(int);
                        return (std::find(primes, end, num) != end);


                        Programming Blog utf8-cpp

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

                        Ah, but in .net (C#) we can use a (generic) dictionary and an enum to further extend the required functionality...

                        public static partial class NumberKeeper
                        {
                            \[System.FlagsAttribute\]
                            public enum NumberProperty
                            {
                                None       =   0
                            ,             
                                Odd        =   1
                            ,
                                Even       =   2
                            ,
                                Positive   =   4
                            ,
                                Negative   =   8
                            ,
                                Prime      =  16
                            ,
                                PowerOfTwo =  32
                            ,
                                Square     =  64
                            ,
                                Cube       = 128
                            ,
                                Fibonacci  = 256
                            ,
                                Factorial  = 512
                        
                                /\* et cetera \*/
                            } ;
                        
                            public static readonly System.Collections.Generic.Dictionary<int,NumberProperty> Numbers ;
                        
                            static NumberKeeper
                            (
                            )
                            {
                                Numbers = new System.Collections.Generic.Dictionary<int,NumberProperty>() ;
                        
                                Numbers.Add (   0 , NumberProperty.None ) ;
                                Numbers.Add (   1 , NumberProperty.Odd  | NumberProperty.Positive                         | NumberProperty.PowerOfTwo | NumberProperty.Fibonacci | NumberProperty.Factorial ) ;
                                Numbers.Add (   2 , NumberProperty.Even | NumberProperty.Positive | NumberProperty.Prime  | NumberProperty.PowerOfTwo | NumberProperty.Fibonacci | NumberProperty.Factorial ) ;
                                Numbers.Add (   3 , NumberProperty.Odd  | NumberProperty.Positive | NumberProperty.Prime                              | NumberProperty.Fibonacci ) ;
                                Numbers.Add (   4 , NumberProperty.Even | NumberProperty.Positive | NumberProperty.Square | NumberProperty.PowerOfTwo ) ;
                                Numbers.Add (   5 , NumberProperty.Odd  | NumberProperty.Positive | NumberProperty.Prime                              | NumberProperty.Fibonacci ) ;
                                Numbers.Add (   6 , NumberProperty.Even | NumberProperty.Positive                                                                                | NumberProperty.Factorial ) ;
                                Numbers.Add (   7 , NumberProperty.Odd  | NumberProperty.Positive | NumberProperty.Prime  ) ;
                                Numbers.Add (   8 , NumberProperty.Even | NumberProperty.Positive | NumberProperty.Cube   | NumberProperty.PowerOfTwo | NumberProperty.Fibonacci ) ;
                                Numbers.Add (   9 , NumberProperty.Odd  | NumberProperty.Positive | NumberProperty.Square ) ;
                                Numbers.Add (  10 , NumberProperty.Even | NumberProperty.
                        
                        A 1 Reply Last reply
                        0
                        • A Andre Ladeira

                          The guy is hidden a genious! He calculated the prime numbers up to 113 without assistance! I would have stopped at 19... :-)

                          S Offline
                          S Offline
                          S Douglas
                          wrote on last edited by
                          #25

                          andre-ladeira wrote:

                          He calculated the prime numbers up to 113 without assistance!

                          :cough: Unlikely ->- Pascal - Response[^] http://en.wikipedia.org/wiki/Prime_number[^]


                          1 Reply Last reply
                          0
                          • E Eric Georgiades

                            as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :

                            if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
                            {
                            return true;
                            }
                            else
                            {
                            return false;
                            }

                            when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?

                            me, myself and my blog - loadx.org ericos g.

                            T Offline
                            T Offline
                            ToddHileHoffer
                            wrote on last edited by
                            #26

                            I do kinda feel sorry for him. I hope you crushed his dreams of being a programmer.

                            GameFly free trial

                            1 Reply Last reply
                            0
                            • E Eric Georgiades

                              as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :

                              if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
                              {
                              return true;
                              }
                              else
                              {
                              return false;
                              }

                              when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?

                              me, myself and my blog - loadx.org ericos g.

                              P Offline
                              P Offline
                              Patrick Etc
                              wrote on last edited by
                              #27

                              Wow

                              1 Reply Last reply
                              0
                              • P PIEBALDconsult

                                Ah, but in .net (C#) we can use a (generic) dictionary and an enum to further extend the required functionality...

                                public static partial class NumberKeeper
                                {
                                    \[System.FlagsAttribute\]
                                    public enum NumberProperty
                                    {
                                        None       =   0
                                    ,             
                                        Odd        =   1
                                    ,
                                        Even       =   2
                                    ,
                                        Positive   =   4
                                    ,
                                        Negative   =   8
                                    ,
                                        Prime      =  16
                                    ,
                                        PowerOfTwo =  32
                                    ,
                                        Square     =  64
                                    ,
                                        Cube       = 128
                                    ,
                                        Fibonacci  = 256
                                    ,
                                        Factorial  = 512
                                
                                        /\* et cetera \*/
                                    } ;
                                
                                    public static readonly System.Collections.Generic.Dictionary<int,NumberProperty> Numbers ;
                                
                                    static NumberKeeper
                                    (
                                    )
                                    {
                                        Numbers = new System.Collections.Generic.Dictionary<int,NumberProperty>() ;
                                
                                        Numbers.Add (   0 , NumberProperty.None ) ;
                                        Numbers.Add (   1 , NumberProperty.Odd  | NumberProperty.Positive                         | NumberProperty.PowerOfTwo | NumberProperty.Fibonacci | NumberProperty.Factorial ) ;
                                        Numbers.Add (   2 , NumberProperty.Even | NumberProperty.Positive | NumberProperty.Prime  | NumberProperty.PowerOfTwo | NumberProperty.Fibonacci | NumberProperty.Factorial ) ;
                                        Numbers.Add (   3 , NumberProperty.Odd  | NumberProperty.Positive | NumberProperty.Prime                              | NumberProperty.Fibonacci ) ;
                                        Numbers.Add (   4 , NumberProperty.Even | NumberProperty.Positive | NumberProperty.Square | NumberProperty.PowerOfTwo ) ;
                                        Numbers.Add (   5 , NumberProperty.Odd  | NumberProperty.Positive | NumberProperty.Prime                              | NumberProperty.Fibonacci ) ;
                                        Numbers.Add (   6 , NumberProperty.Even | NumberProperty.Positive                                                                                | NumberProperty.Factorial ) ;
                                        Numbers.Add (   7 , NumberProperty.Odd  | NumberProperty.Positive | NumberProperty.Prime  ) ;
                                        Numbers.Add (   8 , NumberProperty.Even | NumberProperty.Positive | NumberProperty.Cube   | NumberProperty.PowerOfTwo | NumberProperty.Fibonacci ) ;
                                        Numbers.Add (   9 , NumberProperty.Odd  | NumberProperty.Positive | NumberProperty.Square ) ;
                                        Numbers.Add (  10 , NumberProperty.Even | NumberProperty.
                                
                                A Offline
                                A Offline
                                Andre Ladeira
                                wrote on last edited by
                                #28

                                Is this real c# code or just a joke? I don't know the language but it looks pretty ugly to me...

                                We're in the pipe, five by five - Terran dropship.

                                P 1 Reply Last reply
                                0
                                • P Pascal 0

                                  wikipedia stops at 113 too :) http://en.wikipedia.org/wiki/Prime_number[^]

                                  V Offline
                                  V Offline
                                  Vasudevan Deepak Kumar
                                  wrote on last edited by
                                  #29

                                  - Pascal - wrote:

                                  wikipedia stops at 113 too

                                  13 is considered bad unlucky number. Is 113 fall under this category also? :-D

                                  Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                                  1 Reply Last reply
                                  0
                                  • M mav northwind

                                    And, in addition to being very limited in the range of input values, the result isn't correct, either. <SmartassMode> 1 is not a prime number, by definition. </SmartassMode> ;P

                                    Regards, mav -- Black holes are the places where God divided by 0...

                                    V Offline
                                    V Offline
                                    Vasudevan Deepak Kumar
                                    wrote on last edited by
                                    #30

                                    mav.northwind wrote:

                                    1 is not a prime number, by definition.

                                    It is qualified as Unique Number right?

                                    Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                                    1 Reply Last reply
                                    0
                                    • D dbrenth

                                      Should have told him he has to use this list: The first 10000 prime numbers[^]

                                      Brent

                                      V Offline
                                      V Offline
                                      Vasudevan Deepak Kumar
                                      wrote on last edited by
                                      #31

                                      dbrenth wrote:

                                      The first 10000 prime numbers[^]

                                      And any of the following things would have happened for sure: 1) Typing the if-else clause for 10000 numbers, he would broken the keyboard. 2) Typing the if-else clause for 10000 numbers, he would have broken down and ambulance should have been requested. It is an unnecessary headache, at least in this case right?

                                      Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                                      1 Reply Last reply
                                      0
                                      • G Giorgi Dalakishvili

                                        Ask him to write a function that returns weather or not a given number is even :D

                                        my articles

                                        V Offline
                                        V Offline
                                        Vasudevan Deepak Kumar
                                        wrote on last edited by
                                        #32

                                        Giorgi Dalakishvili wrote:

                                        Ask him to write a function that returns weather or not a given number is even

                                        And for sure, the developer would written the code which would have thrown System.StackOverFlowException :-D

                                        Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                                        1 Reply Last reply
                                        0
                                        • E Eric Georgiades

                                          as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :

                                          if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
                                          {
                                          return true;
                                          }
                                          else
                                          {
                                          return false;
                                          }

                                          when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?

                                          me, myself and my blog - loadx.org ericos g.

                                          A Offline
                                          A Offline
                                          Armin Fryder
                                          wrote on last edited by
                                          #33

                                          He is a genius - always staying in business with a new update of primes!!

                                          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