### Combination list code

Hi, I cannot seem to find a piece of code that would give me this.

Combinations with repetition (n=4, r=4)

List has 35 entries.
{r,r,r,r} {r,r,r,d} {r,r,r,l} {r,r,r,u} {r,r,d,d} {r,r,d,l} {r,r,d,u} {r,r,l,l} {r,r,l,u} {r,r,u,u} {r,d,d,d} {r,d,d,l} {r,d,d,u} {r,d,l,l} {r,d,l,u} {r,d,u,u} {r,l,l,l} {r,l,l,u} {r,l,u,u} {r,u,u,u} {d,d,d,d} {d,d,d,l} {d,d,d,u} {d,d,l,l} {d,d,l,u} {d,d,u,u} {d,l,l,l} {d,l,l,u} {d,l,u,u} {d,u,u,u} {l,l,l,l} {l,l,l,u} {l,l,u,u} {l,u,u,u} {u,u,u,u}

I tried doing it with 4 different FOR loops, but it hangs when I go into the third one. Can you please give me any directions? I may not know the correct search terms, everything I found was combinations without repetitions

this is what I have so far, the program hangs on execution (it works fine until the third FOR loop
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849`` ``````#include #include #include #include using namespace std; int i, j, first, second, third, fourth, count1, count2; char directions[4] = {'R', 'D', 'L', 'U'}; char figures[10][80]; int main() { int count; count1=1; count2=1; for (first=0; first<=3; first++) { for (second=0; second<=3; second++) { for (third=0; third<=3; third++) { for (fourth=0; fourth<=3; fourth++) { figures[count1][count2]=directions[first]; figures[count1][count2+1]=directions[second]; figures[count1][count2+2]=directions[third]; figures[count1][count2+3]=directions[fourth]; count1++; } } } } for (i=0; i<=100; i++) { for (j=0; j<=4; j++) {cout<
Variable `count1` exceeds 9 quite quick.

I don't know how your compiler aligns variables, but it is possible that `figures[count1][count2]` modifies `first` and the cycle never ends.

Try to correct dimensions of array or indexes.
omg, I'm a retard, thanks :)
Topic archived. No new replies allowed.