The following program finds the different arrangements (there are 1157) of the numbers
1,2,3,4,5,6
that produce valid sequences.
#include <iostream>
#include <array>
#include <algorithm>
using namespace std;
enum { N = 24, TS = 84 };
void show(array<int, N> a)
{
int sum = 0;
for ( size_t n = 0; n<N; ++n)
{
sum += a[n];
}
if ( sum == TS )
{
for ( size_t n = 0; n<N; ++n)
{
cout << a[n] << " ";
}
cout << "\n";
}
}
void recurse(int cur_digit, int cur_index, array<int,N> a)
{
if ( cur_index == N)
{
show(a);
return;
}
if ( cur_digit==6)
{
while ( cur_index < N)
{
a[cur_index++] = cur_digit;
}
show(a);
return;
}
while (cur_index < N)
{
a[cur_index++] = cur_digit;
recurse( cur_digit+1, cur_index, a);
for (int n= cur_index; n<N; ++n)
a[n] = 0;
}
}
int main()
{
array<int, N> a{0};
recurse(1, 0, a);
}
Excerpt of the output:
1 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
1 2 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 5
1 2 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 5
1 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 5 5 5
1 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 5 6
1 2 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5
..
1 2 2 2 2 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 5 6
The solution your are looking for, is given by all the
different permutations of each of the above lines. Finding such permutations it's the hard part of the task and it is up to you... :-)