# Thread: Logic to generate a pattern

1. Member
Join Date
Nov 2008
Posts
1
Rep Power
0

## 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. 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. ## 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

4. 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.

#### Posting Permissions

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