Hello folks,
How can I fill a 2D-array (of size [1260][4]) with all variations of 1-10 (which is 5040 variations)?

1 2 3 4
1 2 3 5
1 2 3 6
..
..
1 7 4 9
..


and so on..

Thanks!

>>all variations of 1-10

There are 10! different variations go through them like so :

1 1 1 1
1 1 1 2
1 1 1 3
1 1 1 4
1 1 1 5

and so on

there are 5040 variations.

n!/(n-k)! n=10, k=4. --> 5040

can't be two equal numbers in each series.
so it will look:

1. 1 2 3 4
2. 1 3 2 4
3. 1 3 4 2
4. ......
5. ......
.
.
.
.
5040. 4 2 1 3 (for example)

Isn't 10C4 = 210

Where are you getting 5040?

I know this probably doesn't help but I was just curious as to where
you got the number 5040 from.

it is 10!/6! which is 10•9•8•7 which is 5040.

think about it this way:
you have two cells, you want to fill it with all the permutations of 1-3. you'll get:

1 2
1 3
2 3
2 1
3 1
3 2

6 options, because 3!/(3-2)! is equal to 6.

if you make this calc for 10 and 4 you'll get 5040

@FutureWebDev

There are 210 ways to choose 4 from 10 but there are 24 permutations of each therefor 5040 is correct.

@MarounMaroun

How is your 2D-array (of size [1260][4]) going to hold 5040 combinations?

1260 rows.. 4 columns each.
so each row will hold a permutation.

anyone has an idea of how to implement such a thing?

Maybe it is not best solution. Try to use random number generator for integers. Generate randomly the number from 1 to 9. Then generate second number and compare it with previous one. If it coincide, generate one more and so on till you get four different numbers. After that repeat this procedure and check whether new number is coincided with existed ones if you need that.

This is what you are after possibly.

I don't think next_permutation would work. It will give you the 24 permutations once you have generated the 4-digit number but it won't generate the numbers themselves.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.