Given a character array, I am writing a function that returns the 18 sub-clusters of a given length that come closest to having given numbers of each character type present in the original array (for example, 18 a's, 10 b's, 12 c's, and 5 d's). These 18 clusters must also satisfy three other properties that are irrelevant to the problem I'm having.
To do this, I iterated 18 for-loops (I am too lazy to define this function recursively until it works). For every set of 18 sub-cluster starting points, I assigned the 18 subclusters to a given array, evaluated the array, and if the array came closest to satisfying the four aforementioned conditions, I assigned its subclusters to an 18 position array called bestclustergroup.
When I print bestclustergroup outside of the iterated for-loop, the execution window remains blank. I can't figure out why, considering that bestcluster group is initialized for every set of 18 cluster starting positions.
If I can determine the bug in the reduced test-case below, I'm confident my program will work:
CODE
#include <iostream>
using namespace std;
main (){
int nofposinbestgroup = 18 * 2;
char bestclustergroup [nofposinbestgroup];
char allsingleclusters[] = "aaabacadaeafbabbbcbdbebfcacbcccdcecfdadbdcdddedfeaebecedeeeffafbfcfdfeff";
int positionlimit = 36;
for (long int first = 0; first < positionlimit - 17; ++first){
for (long int second = first + 1; second < positionlimit - 16; ++second){
for (long int third = second + 1; third < positionlimit - 15; ++third){
for (long int fourth = third + 1; fourth < positionlimit - 14; ++fourth){
for (long int fifth = fourth + 1; fifth < positionlimit - 13; ++fifth){
for (long int sixth = fifth + 1; sixth < positionlimit - 12; ++sixth){
for (long int seventh = sixth + 1; seventh < positionlimit - 11; ++seventh){
for (long int eighth = seventh + 1; eighth < positionlimit - 10; ++eighth){
for (long int ninth = eighth + 1; ninth < positionlimit - 9; ++ninth){
for (long int tenth = ninth + 1; tenth < positionlimit - 8; ++tenth){
for (long int eleventh = tenth + 1; eleventh < positionlimit - 7; ++eleventh){
for (long int twelfth = eleventh + 1; twelfth < positionlimit - 6; ++twelfth){
for (long int thirteenth = twelfth + 1; thirteenth < positionlimit - 5; ++thirteenth){
for (long int fourteenth = thirteenth + 1; fourteenth < positionlimit - 4; ++fourteenth){
for (long int fifteenth = fourteenth + 1; fifteenth < positionlimit - 3; ++fifteenth){
for (long int sixteenth = fifteenth + 1; sixteenth < positionlimit - 2; ++sixteenth){
for (long int seventeenth = sixteenth + 1; seventeenth < positionlimit - 1; ++seventeenth){
for (long int eighteenth = seventeenth + 1; eighteenth < positionlimit; ++eighteenth){
long int clusterpositions[18] = {first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth, fifteenth, sixteenth, seventeenth, eighteenth};
//long int clusterpositions[18] = {positionlimit - 18, positionlimit - 17, positionlimit - 16, positionlimit - 15, positionlimit - 14, positionlimit - 13, positionlimit - 12, positionlimit - 11, positionlimit - 10, positionlimit - 9, positionlimit - 8, positionlimit - 7, positionlimit - 6, positionlimit - 5, positionlimit - 4, positionlimit - 3, positionlimit - 2, positionlimit - 1};
for (int position = 0; position < 18; ++position){
for (int lettercounter = 0; lettercounter < 2; ++lettercounter){
int whereinallclusters = clusterpositions[position]*2 + lettercounter;
int whereinbest = position*2 + lettercounter;
char character = allsingleclusters[whereinallclusters];
bestclustergroup[whereinbest] = character;
}}
}}}}}}}}}}}}}}}}}}
for (int where = 0; where < nofposinbestgroup; ++where)
cout << bestclustergroup[where];
return bestclustergroup;
return 0;
}
If anybody could figure out why this program returns me a blank, I would greatly appreciate it. This programming bug has baffled me, a beginner, for days. Thanks.