Let's say I have a list [x1, x2, x3]
where x1
, x2
, and x3
can take on any value between 1 and 5.
I want to iterate over every possible list that can be created (From [1, 1, 1]
, [1, 1, 2]
, . To [5, 5, 5]
). This is an easy problem with only 3 elements in the list.
You can do something like this:
for x = 1; x <= 5; x++;
for y = 1; y <= 5; y++;
...
for q = 1; q <= 5; q++;
create list [x, y, ..., q];
do something with the list;
However, how do you iterate over every possible list where the number of elements is over like 10?
Edi: I've added Java as a constraint. I just want to see how this would be done without too many fancy library calls.
Edit2: What I am really looking for is some algorithm to do this, not what sort of libraries can be used to do it. But what I'm looking for is really a language-independent algorithm.