Combinations

how do i create all the combination of numbers including repeats given n numbers and k digits, without using #include algorithm and storing them in a vector?

Eg- n = 0,1,2,3,4,5 and k = 4

There will be 1296 possible combinations.
0000 to 5555

Thank you
You could probably use a similar algorithm as you would use when incrementing a number by hand. The only difference is that you've only got 6 digits instead of 10.
its not 0000 to 5555, though, as 1999 wouldnt work?

I would put the possible digits in a container (a string will do, for this, or an array, whatever) and iterate over that.
then you get
0000
0001
0002
0003
0004
0005 <- 5 is the last one in the container, trigger: increment next value and start over:
0010
0011
0012
...
0055
0100
...

stop when all 4 values are equal to the last item.

there is probably a cute way to do it with logs. these are base 6 numbers, in this case?? If you logged out from 0 to 1295, maybe? I think you need a lookup table to do it that way, though.

Last edited on
Thank you
Topic archived. No new replies allowed.