Results 1 to 4 of 4
  1. #1
    vijay_2008 is offline Member
    Join Date
    Nov 2008
    Posts
    1
    Rep Power
    0

    Default Logic to generate a pattern

    Hi All,
    The requirement is something like this.......
    Example:
    Sum = 7
    Availability Matrix = [5, 4, 6, 1]

    Required: I need all set of possible unique combinations that sums to 7.

    Few example combinations: [5, 2, 0, 0], [4, 3, 0, 0], [3, 4, 0, 0]

    I also have a few questions...
    ? Can we tell the number of unique number of solutions that can be formed well in advance.
    ? There are many solutions to this problem which one would be the good in terms of performance imagine when the availabilty matrix is huge

    Early help would be appreciated.


    Thanks,
    V
    :)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default

    Don't understand the problem statement.
    If you are given a list with the 4 numbers [5, 4, 6, 1]
    how do you get [5, 2, 0, 0],
    There is no 2 in the given list.
    How many of the numbers in the list can be used?
    Can numbers outside of the list be used?

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Not understanding...

    yeah... I'd have to agree with Norm... I'm not understanding. From the description you posted, it would appear that you can only pick the numbers from the availability matrix. If that is the case, what I would is:
    • create a copy of the availability matrix (lets call it "prime" matrix)
    • with two for loops, add every array element in the availability matrix with every array element in the prime matrix
    • check every addition for an equivalency to 7
    • when this condition is met, print out the elements of each array

    Does this help?
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    See Sedgewick, great discussion in very readable work that brings great clarity to when and where to use what algorithms to huge availability.

    In general, the number of nodes vis-a-vis the raw edge count defines the general approach.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Similar Threads

  1. problem with <logic:iterate> tag looping
    By tsaswathy in forum Web Frameworks
    Replies: 0
    Last Post: 09-27-2008, 12:13 PM
  2. Cant get the logic right
    By jermaindefoe in forum New To Java
    Replies: 4
    Last Post: 03-11-2008, 12:22 AM
  3. iterate HashMap with logic
    By Heather in forum Web Frameworks
    Replies: 2
    Last Post: 07-03-2007, 09:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •