#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef unsigned short USHORT;
#define BIN_LEN 30
#define FALSE 0
#define TRUE !FALSE
int SearchThreeRepeats( USHORT i, char *BinStr )
{
USHORT p = 1;
char Buf[(BIN_LEN / 3) + 1],
OldBuf[(BIN_LEN / 3) + 1] = "";
USHORT j;
for ( j = 0; j < BIN_LEN; j += i ) {
strncpy( Buf, BinStr + j, i );
Buf[i] = 0;
if ( strcmp( OldBuf, Buf ) == NULL )
p++;
else
p = 1;
strcpy( OldBuf, Buf );
if ( p == 3 )
return( TRUE );
}
return( FALSE );
}
int CheckRepeatTriad( char *BinStr )
{
USHORT i;
for ( i = 1; i <= BIN_LEN / 3; i++ ) {
if ( SearchThreeRepeats( i, BinStr ) )
return( TRUE );
}
return( FALSE );
}
int main(int argc, char* argv[])
{
USHORT i;
char BinStr[BIN_LEN + 1] = "";
char c[2];
randomize();
do {
while ( TRUE ) {
for ( i = 0; i < BIN_LEN; i++ ) {
itoa( rand() % 2, c, 2 );
BinStr[i] = c[0];
}
BinStr[BIN_LEN] = 0;
if ( ! CheckRepeatTriad( BinStr ) )
break;
}
printf( "Binary String = %s\nNew String (Y/N)?\n", BinStr );
} while ( getch() != 'Y' );
return 0;
}