There might be a more parsimonious solution, but I think this code works as per your description of the problem.
Make sure that the worksheet with the input data is active and all three columns exist before you run it.
J...
void cb(){
//make some datasets attached to columns of active sheet as you described.
Worksheet wks=Project.ActiveLayer();
Dataset dsIn, ds1, ds0;
dsIn.Attach(wks,0);
ds1.Attach(wks, 1);
ds0.Attach(wks, 2);
ds0.SetSize(dsIn.GetSize());
ds1.SetSize(dsIn.GetSize());
ds0=NANUM;
ds1=NANUM;
//declare some counters.
int iOneCount=0; //number of 'periods of 1s' observed.
int iZeroCount=0; //number of 'periods of 0s' observed.
int iSame=1; //number of observations in current period.
for (int j=1;j<dsIn.GetSize();j++){ //progress through entire input column.
if (dsIn[j]!=dsIn[j-1]){ //if current value does not equal previous, change has occured.
if (dsIn[j-1]==1){ //change was from 1 to 0 so output to 1s counter.
ds1[iOneCount++]=iSame;
}
else{ //change was from 0 to 1 so output to 0s coutner.
ds0[iZeroCount++]=iSame;
}
iSame=1; //output of period complete, so reset streak counter.
}
else iSame++; //no change occured, so increment streak counter.
}
//finally, take care of the last period.
if (dsIn[j-1]==1){
ds1[iOneCount++]=iSame;
}
else{
ds0[iZeroCount++]=iSame;
}
ds0.SetSize(iZeroCount);
ds1.SetSize(iOneCount);
}