There's are 2 positive integers x and y we have to generate a pattern that looks like,
2,3,3,2,3,3,3,2,3,3,3,2,3,3,2,3,3,3,2,3,3,3,2,3,3,3,2,3,3,2....
If we look at the count of 3s inbetween 2s we can see the same pattern is created,
2 | 3 3 | 2 | 3 3 3 | 2 | 3 3 3 | 2 ......
What I have tried:
#include <iostream.h>
#include <conio.h>
void main() {
clrscr();
int x = 5, y = 6;
int u = x, l = 0, k = 0, j = x;
while(k < 21) {
cout<<x<<",";
if(u == x && l > 0) {
u = y;
l = 0;
}
if(u == y && l == j) {
if(j == x) {
j = y;
} else {
j = x;
}
u = x;
l = 0;
}
for(int i=0; i<u; i++) {
cout<<y<<",";
}
l++;
k++;
cout<<endl;
}
getch();
}
It's working but I don't think its the optimal way to do it.