//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void TForm1::main() { char *stime[30],*etime[30]; __int64 tick1,tick2; tick1 = GetTickCount(); Form1->Cursor = crHourGlass; fid = fopen("log.txt","wt"); time(&t1); *stime = ctime(&t1); fprintf(fid,"*** pazul started : %s \n",*stime); Edit1->Text = *stime; Edit3->Text = IntToStr(time(&t2)-t1); Form1->Refresh(); exec(); tick2 = GetTickCount(); result = (int) (tick2 -tick1); time(&t2); *etime = ctime(&t2); fprintf(fid,"\n*** pazul ended time = %d ms : %s \n",result,*etime); Edit2->Text = *etime; Edit3->Text = IntToStr(t2-t1); Edit4->Text = IntToStr(result); fclose(fid); // reset cursor mark Form1->Cursor = crDefault; } //--------------------------------------------------------------------------- void TForm1::exec() { int m; init(); for (m=22; m<=48; m++) { if (Search(m) == 0) break; } } //--------------------------------------------------------------------------- void TForm1::init() { int i,j,k,c,t,w,ww,T[1000],orig[26]; Qmax = 0; for (k=0; k<4096; k++) { //4096 = 4^6 c = 0; w = k; while (w > 0) { ww = w & 0x03; if (ww == 3) break; c += ww; w = w >> 2; } if (w == 0) T[++Qmax] = (c << 16) + k; } //Sort T[] for (i=1; i> 16; Q[k].pat = T[k] & 0xffff; w = Q[k].pat; for (i=1; i<=6; i++) { c = w & 0x03; w = w >> 2; (i <= 3)? orig[i] = c : orig[i+2] = c; } orig[13] = 1; //B part orig[ 5] = orig[1]; orig[10] = orig[2]; orig[15] = orig[3]; orig[ 4] = orig[6]; orig[ 9] = orig[7]; orig[14] = orig[8]; //C part orig[21] = orig[1]; orig[16] = orig[2]; orig[11] = orig[3]; orig[22] = orig[6]; orig[17] = orig[7]; orig[12] = orig[8]; //D part orig[25] = orig[1]; orig[24] = orig[2]; orig[23] = orig[3]; orig[20] = orig[6]; orig[19] = orig[7]; orig[18] = orig[8]; if (k < -3) printM("*** orig ***",orig); for (t=0; t<27; t++) Norm(t,orig,k); } //Qix stup c = -1; for (k=1; k<=Qmax; k++) { if (c == Q[k].m) continue; c = Q[k].m; Qix[c] = k; fprintf(fid," %2d %4d\n",c,k); } Qix[c+1] = Qmax+1; fprintf(fid,"\n"); } //--------------------------------------------------------------------------- void TForm1::Norm(int T,int orig[],int pos) { int i,j,k,n,c,N[28]; // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 const p1[] = {0,1,1,2,2,1,1,2,1,1,0,2,1,0,2,1,2,1,2,2,0,1,0,1,0,0}; const p2[] = {0,1,0,0,0,2,2,2,0,1,1,1,2,0,1,2,1,1,0,2,2,0,2,0,1,0}; const p3[] = {0,0,1,0,2,0,2,2,0,1,1,2,1,0,2,1,1,1,0,2,2,2,0,0,0,1}; i = T % 3; j = (T / 3) % 3; k = (T / 9) % 3; for (n=1; n<=25; n++) { N[n] = (orig[n] + p1[n]*i + p2[n]*j + p3[n]*k) % 3; } Q[pos].a[T] = N[ 1] + N[ 2] + N[ 3] + N[ 6] + N[ 7] + N[ 8]; Q[pos].b[T] = N[ 5] + N[10] + N[15] + N[ 4] + N[ 9] + N[14]; Q[pos].c[T] = N[21] + N[16] + N[11] + N[22] + N[17] + N[12]; Q[pos].d[T] = N[25] + N[24] + N[23] + N[20] + N[19] + N[18]; if (pos < -3) printM("**** Norm *****",N); } //--------------------------------------------------------------------------- int TForm1::Search(int M) { int a,b,c,d,ia,ib,ic,id,t,n; for (a=(M+3)/4; a<=12; a++) { for (b=0; b<=a; b++) { // if (a+b < (M+1)/2) continue; for (c=0; c<=a; c++) { d = M - a - b - c; if ((d < 0) || (d > a)) continue; if ((a == d) && (b < c)) continue; fprintf(fid,"++++ %d (%d,%d,%d,%d) \n",M,a,b,c,d); fflush(fid); for (ia=Qix[a]; ia