Stumped on combinations

J

Joosy

Hi

I am stumped on a complex combination problem. I need to create all possible
combinations to fill grids 7 columns wide with set parameter restrictions.

Parameters are: 1) the number of columns the grid will take 2) the number of
times 'x' is to appear in the columns, going downwards 3) the maximum number
of spaces before an 'x' 4) the minimum number of 'x' in a row 5) the maximum
number of x in a row.

For example BuildGrids(3,1,6,2,3) might produce

000000x - this row has six spaces
x00xxx0 - this row has three x
0xx0000 - this row has two xs

Each column contains one and only one 'x' the maximum number of spaces is 6,
the minimum number of times 'x' appears together is 2.

This should keep producing different combinations that fit the rules until
all possible combinations are exhausted.

In the variations produced, we don't need to achieve either the maximum or
minimum number of x in a row. It just need to fall within the parameters.



BuildGrid(4,2,4,1,6) might produce

00xx00x
xx00xxx
xxx0xx0
000x000

The combination of rows two and three produce six x in a row.
 
T

Tyro

Would the formula 2^7 help you? 2^7 = 128 combinations
As in: 000000x, 00000x0, 00000xx, 0000x00, 0000x0x, 0000xx0, 0000xxx,
000x000 etc? This is binary arithmetic.

Tyro
 
J

Joosy

Perhaps if I was 35 years closer to learning advanced maths...

However, it is a start. If I start on something smaller (say, on a scale of
2^4), I may be able to work it out.

--
Stevie

"Build a man a fire and he will be warm for one night. Set a man on fire,
and he will be warm for the rest of his life."

~ Sun-Tzu on Fire
 
J

Joosy

OK, I have stage one working now and can generate all the 0X0.... <bg>
required. The rest should just be a case of pruning out data that don't fit
the rules on the fly and add the remainder to an array before creating
combinations and pruning the combinations using the same rules.

Anyone know where to grab a ready rolled function to pull all possible
combinations and permutations of elements in as array using a parameter of
the number of elements in a group?

Example, CombArray(2) in a three element array (1,2,3) would return:

12
13
21
23
31
21
 
B

Bob I

Joosy said:
Hi

I am stumped on a complex combination problem. I need to create all possible
combinations to fill grids 7 columns wide with set parameter restrictions.

Parameters are: 1) the number of columns the grid will take 2) the number of
times 'x' is to appear in the columns, going downwards 3) the maximum number
of spaces before an 'x' 4) the minimum number of 'x' in a row 5) the maximum
number of x in a row.

For example BuildGrids(3,1,6,2,3) might produce

000000x - this row has six spaces
x00xxx0 - this row has three x
0xx0000 - this row has two xs

Each column contains one and only one 'x' the maximum number of spaces is 6,
the minimum number of times 'x' appears together is 2.

This should keep producing different combinations that fit the rules until
all possible combinations are exhausted.

In the variations produced, we don't need to achieve either the maximum or
minimum number of x in a row. It just need to fall within the parameters.



BuildGrid(4,2,4,1,6) might produce

00xx00x
xx00xxx
xxx0xx0
000x000

The combination of rows two and three produce six x in a row.

There seems to be some rules that are not true. For instance

000000x - this row has six spaces violates

minimum number of times 'x' appears together is 2


xx00xxx
xxx0xx0
The combination of rows two and three produce six x in a row. violates

Each column contains one and only one 'x'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top