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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <string>
#include <iostream>
#include <stdio.h>
#include <string.h>

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<<figures[i][j];}
     cout<<endl;
   }
    
	system("pause");
 
	return 0;
}
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.