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. General Programming
  3. C / C++ / MFC
  4. Difficult computer science problem

Difficult computer science problem

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresgraphicsalgorithmshelpquestion
30 Posts 10 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.
  • T toxcct

    to the paper next to the keyboard...


    TOXCCT >>> GEII power

    [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #16

    That'll work! It satisfies the requirements of not using a list, array, etc. :-D


    "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

    "Judge not by the eye but by the heart." - Native American Proverb

    1 Reply Last reply
    0
    • S Semion_N

      the problem says that you mustn't use arrays or other allocation of memory.

      SnaidiS(Semion)

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #17

      then, no chance to resolve it ;P


      TOXCCT >>> GEII power

      [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

      S 1 Reply Last reply
      0
      • S Semion_N

        Does anyone know an algorithm that recieves an unknown amount of numbers(it stops when it recieves -1) and calculates how many of them are above the average without using an array, list, vector, stack, file ect.? Is it even possible?

        SnaidiS(Semion)

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #18

        So what kind of storage are you allowed to use?

        --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        S 1 Reply Last reply
        0
        • M Michael Dunn

          So what kind of storage are you allowed to use?

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

          S Offline
          S Offline
          Semion_N
          wrote on last edited by
          #19

          just variables. int, float,char..

          SnaidiS(Semion)

          1 Reply Last reply
          0
          • T toxcct

            then, no chance to resolve it ;P


            TOXCCT >>> GEII power

            [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

            S Offline
            S Offline
            Semion_N
            wrote on last edited by
            #20

            You say that there is no chanse to resolve it so can you prove it mathematiclly?

            SnaidiS(Semion)

            T H 2 Replies Last reply
            0
            • S Semion_N

              You say that there is no chanse to resolve it so can you prove it mathematiclly?

              SnaidiS(Semion)

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #21

              i'm tired with your thread... go find someone else to bore


              TOXCCT >>> GEII power

              [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

              1 Reply Last reply
              0
              • S Semion_N

                Does anyone know an algorithm that recieves an unknown amount of numbers(it stops when it recieves -1) and calculates how many of them are above the average without using an array, list, vector, stack, file ect.? Is it even possible?

                SnaidiS(Semion)

                L Offline
                L Offline
                led mike
                wrote on last edited by
                #22

                Can't you keep a running total and the number of inputs in two variables. Then you can calculate the average and of course half the number of variables is above the average. Or am I missing something?

                led mike

                T D 2 Replies Last reply
                0
                • L led mike

                  Can't you keep a running total and the number of inputs in two variables. Then you can calculate the average and of course half the number of variables is above the average. Or am I missing something?

                  led mike

                  T Offline
                  T Offline
                  toxcct
                  wrote on last edited by
                  #23

                  missing something calculating the average "on the run" is easy to do with a float and an integer. but to tell how many of the inputs were upper than the average... no chance if you don't store the datas...


                  TOXCCT >>> GEII power

                  [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

                  L 1 Reply Last reply
                  0
                  • S Semion_N

                    Does anyone know an algorithm that recieves an unknown amount of numbers(it stops when it recieves -1) and calculates how many of them are above the average without using an array, list, vector, stack, file ect.? Is it even possible?

                    SnaidiS(Semion)

                    M Offline
                    M Offline
                    Maximilien
                    wrote on last edited by
                    #24

                    it's not possible; as soon as you receive a new number the average will be modified, and since you cannot keep an history of the values already read, there is no way of determining what numbers that you already read that are above or below the average. (unproven, and unverified ) The problem with the average is that you can have a new value that will completly "unbalance" the computed average, for example you have a series of values in the [1, 10] range, the average will be between those 2 values, but if at some point you have a very large value, it will mess the result, and statistically the result will not be valid, unless you can filter out those bad values. ( but I expect someone to come with a brilliant mathematical answer that will awe us )


                    Maximilien Lincourt Your Head A Splode - Strong Bad

                    1 Reply Last reply
                    0
                    • L led mike

                      Can't you keep a running total and the number of inputs in two variables. Then you can calculate the average and of course half the number of variables is above the average. Or am I missing something?

                      led mike

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #25

                      led mike wrote:

                      ...of course half the number of variables is above the average. Or am I missing something?

                      That outliers can skew things quite a bit. Given the set {1, 2, 5, 7, 10, 18}, the average is 7.1. Four numbers in the set are below this, and two numbers are above.


                      "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                      "Judge not by the eye but by the heart." - Native American Proverb

                      1 Reply Last reply
                      0
                      • S Semion_N

                        Does anyone know an algorithm that recieves an unknown amount of numbers(it stops when it recieves -1) and calculates how many of them are above the average without using an array, list, vector, stack, file ect.? Is it even possible?

                        SnaidiS(Semion)

                        B Offline
                        B Offline
                        benjymous
                        wrote on last edited by
                        #26

                        I'm guessing recursion is your friend here, assuming a magic computer that'll never stack overflow Pseudo-C-ish-code

                        above_average = 0;

                        void main()
                        {
                        doit(0,0)
                        print( above_average " of your numbers were above average )
                        }

                        int doit( int sum, int count )
                        {
                        print( "enter number, -1 to end" );
                        int input
                        get input from keyboard

                        int average;
                        if input == -1
                        {
                        average = sum/count
                        }
                        else
                        {
                        average = doit(sum+input, count+1)
                        if( input > average )
                        {
                        above_average++
                        }
                        }
                        return average
                        }

                        Now remember, your lecturer is probably reading these forums.... (Technically, this is using a stack, just not the kind of stack most people would think of!)

                        -- Help me! I'm turning into a grapefruit! Buzzwords!

                        D C 2 Replies Last reply
                        0
                        • B benjymous

                          I'm guessing recursion is your friend here, assuming a magic computer that'll never stack overflow Pseudo-C-ish-code

                          above_average = 0;

                          void main()
                          {
                          doit(0,0)
                          print( above_average " of your numbers were above average )
                          }

                          int doit( int sum, int count )
                          {
                          print( "enter number, -1 to end" );
                          int input
                          get input from keyboard

                          int average;
                          if input == -1
                          {
                          average = sum/count
                          }
                          else
                          {
                          average = doit(sum+input, count+1)
                          if( input > average )
                          {
                          above_average++
                          }
                          }
                          return average
                          }

                          Now remember, your lecturer is probably reading these forums.... (Technically, this is using a stack, just not the kind of stack most people would think of!)

                          -- Help me! I'm turning into a grapefruit! Buzzwords!

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #27

                          benjymous wrote:

                          (Technically, this is using a stack, just not the kind of stack most people would think of!)

                          Declaring variables and calling functions would violate the "no stack" requirement! Nice solution, BTW.


                          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                          "Judge not by the eye but by the heart." - Native American Proverb

                          1 Reply Last reply
                          0
                          • B benjymous

                            I'm guessing recursion is your friend here, assuming a magic computer that'll never stack overflow Pseudo-C-ish-code

                            above_average = 0;

                            void main()
                            {
                            doit(0,0)
                            print( above_average " of your numbers were above average )
                            }

                            int doit( int sum, int count )
                            {
                            print( "enter number, -1 to end" );
                            int input
                            get input from keyboard

                            int average;
                            if input == -1
                            {
                            average = sum/count
                            }
                            else
                            {
                            average = doit(sum+input, count+1)
                            if( input > average )
                            {
                            above_average++
                            }
                            }
                            return average
                            }

                            Now remember, your lecturer is probably reading these forums.... (Technically, this is using a stack, just not the kind of stack most people would think of!)

                            -- Help me! I'm turning into a grapefruit! Buzzwords!

                            C Offline
                            C Offline
                            Chris Losinger
                            wrote on last edited by
                            #28

                            nice

                            image processing | blogging

                            1 Reply Last reply
                            0
                            • T toxcct

                              missing something calculating the average "on the run" is easy to do with a float and an integer. but to tell how many of the inputs were upper than the average... no chance if you don't store the datas...


                              TOXCCT >>> GEII power

                              [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

                              L Offline
                              L Offline
                              led mike
                              wrote on last edited by
                              #29

                              ooops :->

                              led mike

                              1 Reply Last reply
                              0
                              • S Semion_N

                                You say that there is no chanse to resolve it so can you prove it mathematiclly?

                                SnaidiS(Semion)

                                H Offline
                                H Offline
                                Hamid Taebi
                                wrote on last edited by
                                #30

                                Do you have any idea about it?:)


                                WhiteSky


                                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