I'm wondering if you could give me a hand with an algorithm.

I need to write a algorithm for generating combinations from n number of sets (of integers).

I can write code that will take my fixed number of sets and produce the combinations but Im lost on how I would be able to do this for n number of sets.

I've attached code for generating combinations from a fixed number of sets.

In pseudo code it could look something like this :

function(n, sets, combination)
if n is max then print combination
else
for every element in the n-th set from sets
set the n-th value in the combination to that element
call function(n + 1, sets, combination)
end for
end else
end function

0

Featured Post

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

This algorithm (in C#) will resize any image down to a given size while maintaining the original aspect ratio. The maximum width and max height are both optional but if neither are given, the original image is returned.
This example is designed t…

Okay. So what exactly is the problem here?
How often have we come across situations where we need to know if two strings are 'similar' but not necessarily the same? I have, plenty of times. Until recently, I thought any functionality like that wo…

In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.
https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt
https://filedb.experts-exchange.com/incoming/201…