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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. The Lounge
  3. Combination coding problem

Combination coding problem

Scheduled Pinned Locked Moved The Lounge
data-structureshelp
11 Posts 6 Posters 1 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.
  • M Offline
    M Offline
    mmh1333
    wrote on last edited by
    #1

    I have a coding problem that is hard to solve

    Given an array of positive integers arr[900, 800, 700, 600, 500, 90, 80, 70, 60, 50, 9, 8, 7, 6, 5, 4, 3, 2, 1] anda sum 3400, find all unique combinations in the arr[] where the sum is equal to 3400. The same repeated number may be chosen from arr[] at most 5 times or thereafter x times-multiple(number), or excluded if not possible. Elements in a combination (a1, a2, …, ak) must be printed in non-descending order. (ie, a1 <= a2 <= … <= ak).
    The combinations themselves must be sorted in ascending order, i.e., the combination with smallest first element should be printed first. If there is no combination possible the print “Empty” (without quotes).

    Examples:

    Input : arr[] = 2, 4, 5, 6, 8
    x = 10
    Output : [2, 2, 2, 2,2]
    [2, 4,4]
    [4, 6]
    [5,5]

    the challenge in this problem is to list the numbers or exclude them for the large sum when there is small numbers like 2, 4, 5

    Mike HankeyM P R M 4 Replies Last reply
    0
    • M mmh1333

      I have a coding problem that is hard to solve

      Given an array of positive integers arr[900, 800, 700, 600, 500, 90, 80, 70, 60, 50, 9, 8, 7, 6, 5, 4, 3, 2, 1] anda sum 3400, find all unique combinations in the arr[] where the sum is equal to 3400. The same repeated number may be chosen from arr[] at most 5 times or thereafter x times-multiple(number), or excluded if not possible. Elements in a combination (a1, a2, …, ak) must be printed in non-descending order. (ie, a1 <= a2 <= … <= ak).
      The combinations themselves must be sorted in ascending order, i.e., the combination with smallest first element should be printed first. If there is no combination possible the print “Empty” (without quotes).

      Examples:

      Input : arr[] = 2, 4, 5, 6, 8
      x = 10
      Output : [2, 2, 2, 2,2]
      [2, 4,4]
      [4, 6]
      [5,5]

      the challenge in this problem is to list the numbers or exclude them for the large sum when there is small numbers like 2, 4, 5

      Mike HankeyM Offline
      Mike HankeyM Offline
      Mike Hankey
      wrote on last edited by
      #2

      Hmmm, it seems homework hasn't changed much over the years.

      The less you need, the more you have. Even a blind squirrel gets a nut...occasionally. JaxCoder.com

      1 Reply Last reply
      0
      • M mmh1333

        I have a coding problem that is hard to solve

        Given an array of positive integers arr[900, 800, 700, 600, 500, 90, 80, 70, 60, 50, 9, 8, 7, 6, 5, 4, 3, 2, 1] anda sum 3400, find all unique combinations in the arr[] where the sum is equal to 3400. The same repeated number may be chosen from arr[] at most 5 times or thereafter x times-multiple(number), or excluded if not possible. Elements in a combination (a1, a2, …, ak) must be printed in non-descending order. (ie, a1 <= a2 <= … <= ak).
        The combinations themselves must be sorted in ascending order, i.e., the combination with smallest first element should be printed first. If there is no combination possible the print “Empty” (without quotes).

        Examples:

        Input : arr[] = 2, 4, 5, 6, 8
        x = 10
        Output : [2, 2, 2, 2,2]
        [2, 4,4]
        [4, 6]
        [5,5]

        the challenge in this problem is to list the numbers or exclude them for the large sum when there is small numbers like 2, 4, 5

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

        Even if you were to post this in a the correct place, we won't do your homework for you. What about [ 2 , 2 , 2 , 4 ] and [ 2 , 8 ] ? Where did [ 4 , 6 ] come from?

        E R M 3 Replies Last reply
        0
        • P PIEBALDconsult

          Even if you were to post this in a the correct place, we won't do your homework for you. What about [ 2 , 2 , 2 , 4 ] and [ 2 , 8 ] ? Where did [ 4 , 6 ] come from?

          E Offline
          E Offline
          ElectronProgrammer
          wrote on last edited by
          #4

          PIEBALDconsult wrote:

          Where did [ 4 , 6 ] come from?

          Maybe that is what makes it "hard to solve"?!? Because the OP clearly understands the problem (as demonstrated by the rest of the example). Or maybe I am the one not understanding something :confused:

          M 1 Reply Last reply
          0
          • P PIEBALDconsult

            Even if you were to post this in a the correct place, we won't do your homework for you. What about [ 2 , 2 , 2 , 4 ] and [ 2 , 8 ] ? Where did [ 4 , 6 ] come from?

            R Offline
            R Offline
            Rick York
            wrote on last edited by
            #5

            I think 2+4 is 6, from [2,4,4].

            "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

            1 Reply Last reply
            0
            • M mmh1333

              I have a coding problem that is hard to solve

              Given an array of positive integers arr[900, 800, 700, 600, 500, 90, 80, 70, 60, 50, 9, 8, 7, 6, 5, 4, 3, 2, 1] anda sum 3400, find all unique combinations in the arr[] where the sum is equal to 3400. The same repeated number may be chosen from arr[] at most 5 times or thereafter x times-multiple(number), or excluded if not possible. Elements in a combination (a1, a2, …, ak) must be printed in non-descending order. (ie, a1 <= a2 <= … <= ak).
              The combinations themselves must be sorted in ascending order, i.e., the combination with smallest first element should be printed first. If there is no combination possible the print “Empty” (without quotes).

              Examples:

              Input : arr[] = 2, 4, 5, 6, 8
              x = 10
              Output : [2, 2, 2, 2,2]
              [2, 4,4]
              [4, 6]
              [5,5]

              the challenge in this problem is to list the numbers or exclude them for the large sum when there is small numbers like 2, 4, 5

              R Offline
              R Offline
              Rick York
              wrote on last edited by
              #6

              Questions about programming should be posted in the Q&A section for the language required.

              "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

              1 Reply Last reply
              0
              • M mmh1333

                I have a coding problem that is hard to solve

                Given an array of positive integers arr[900, 800, 700, 600, 500, 90, 80, 70, 60, 50, 9, 8, 7, 6, 5, 4, 3, 2, 1] anda sum 3400, find all unique combinations in the arr[] where the sum is equal to 3400. The same repeated number may be chosen from arr[] at most 5 times or thereafter x times-multiple(number), or excluded if not possible. Elements in a combination (a1, a2, …, ak) must be printed in non-descending order. (ie, a1 <= a2 <= … <= ak).
                The combinations themselves must be sorted in ascending order, i.e., the combination with smallest first element should be printed first. If there is no combination possible the print “Empty” (without quotes).

                Examples:

                Input : arr[] = 2, 4, 5, 6, 8
                x = 10
                Output : [2, 2, 2, 2,2]
                [2, 4,4]
                [4, 6]
                [5,5]

                the challenge in this problem is to list the numbers or exclude them for the large sum when there is small numbers like 2, 4, 5

                M Offline
                M Offline
                MarkTJohnson
                wrote on last edited by
                #7

                Normally we'd point to the Lounge Rules post at the top of the page, but it's missing. Where'd it go? Also dude, if you don't have the mental determination to work out your own problems, I'm not sure that this would be the career for you.

                I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.

                M 1 Reply Last reply
                0
                • P PIEBALDconsult

                  Even if you were to post this in a the correct place, we won't do your homework for you. What about [ 2 , 2 , 2 , 4 ] and [ 2 , 8 ] ? Where did [ 4 , 6 ] come from?

                  M Offline
                  M Offline
                  mmh1333
                  wrote on last edited by
                  #8

                  Its an example.....recursion and backtracking would ring the bell not loudly!

                  P 1 Reply Last reply
                  0
                  • E ElectronProgrammer

                    PIEBALDconsult wrote:

                    Where did [ 4 , 6 ] come from?

                    Maybe that is what makes it "hard to solve"?!? Because the OP clearly understands the problem (as demonstrated by the rest of the example). Or maybe I am the one not understanding something :confused:

                    M Offline
                    M Offline
                    mmh1333
                    wrote on last edited by
                    #9

                    yah! focusing on the example to get a hint is a way of the novice, good try!

                    1 Reply Last reply
                    0
                    • M MarkTJohnson

                      Normally we'd point to the Lounge Rules post at the top of the page, but it's missing. Where'd it go? Also dude, if you don't have the mental determination to work out your own problems, I'm not sure that this would be the career for you.

                      I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.

                      M Offline
                      M Offline
                      mmh1333
                      wrote on last edited by
                      #10

                      This is a valid discussion topic; I didn't post the codes here.. I don't claim to be the master of the art...and about mental determination how about you come up with your own coding reality instead of learning others' work and boasting to be its master...

                      1 Reply Last reply
                      0
                      • M mmh1333

                        Its an example.....recursion and backtracking would ring the bell not loudly!

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

                        That's not how coding specs work.

                        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