C code for Moser: Difference between revisions

From Polymath Wiki
Jump to navigationJump to search
New page: #include <stdio.h> #include <stdlib.h> #include <string.h> #define NUM_LINES_3D 49 →‎stat[i] is 0,1,2,3 depending on whether i (represented base 3) is of type a,b,c,d.: const i...
 
No edit summary
 
Line 13: Line 13:
  int main()
  int main()
  {
  {
   /* There are NUM_LINES_3D lines in [3]^3.  Let's create their bitmasks...
   /* There are NUM_LINES_3D lines in [3]^3.  Let's create their bitmasks... */


   long line_bitmasks[NUM_LINES_3D];
   long line_bitmasks[NUM_LINES_3D];

Latest revision as of 19:34, 7 June 2009

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUM_LINES_3D 49
/* stat[i] is 0,1,2,3 depending on whether i (represented base 3) is of type a,b,c,d. */
const int stat[27] = {0,1,0, 1,2,1, 0,1,0,
                      1,2,1, 2,3,2, 1,2,1,
                      0,1,0, 1,2,1, 0,1,0};
int main()
{
  /* There are NUM_LINES_3D lines in [3]^3.  Let's create their bitmasks... */
 long line_bitmasks[NUM_LINES_3D];
 int i,j,k,count=0;
 long i_bit, j_bit, k_bit;
  for (i=0, i_bit=1; i < 27; i++, i_bit *= 2)
	for (j=0, j_bit=1; j < 27; j++, j_bit *= 2)
		for (k=0, k_bit=1; k<27; k++, k_bit *= 2)
			if (((i%3)+(k%3)-2*(j%3)) == 0)
				if ((((i/3)%3)+((k/3)%3)-2*((j/3)%3))==0)
					if ((((i/9)%3)+((k/9)%3)-2*((j/9)%3))==0)
						if (i < k)
							{
								line_bitmasks[count] = i_bit + j_bit + k_bit;
								count++;
							}
/* There are 2^27 sets in [3]^3.   */
long NUM_SETS_3D = 1;
for (i=0; i<27; i++) NUM_SETS_3D *= 2;
  /* Now searching for line-free sets in [3]^3 by brute force. */
 long set, num_linefree = 0, tmpset;
 long numstat[9][13][7][2];  /* numstat[a][b][c][d] is the number of Moser sets with statistics (a,b,c,d) */
 int a,b,c,d,s[4];
/* Initialise numstat */
for (a=0; a<9; a++)
	for (b=0; b<13; b++)
		for (c=0; c<7; c++)
			for (d=0; d<2; d++)
				numstat[a][b][c][d]=0;


   for (set=0; set<NUM_SETS_3D; set++)  /* Loop through all sets */
	{
// it was marginally faster to put in these 49 lines in by hand rather than create a loop.
		if ((set & line_bitmasks[0]) == line_bitmasks[0]) continue;
		if ((set & line_bitmasks[1]) == line_bitmasks[1]) continue;
		if ((set & line_bitmasks[2]) == line_bitmasks[2]) continue;
		if ((set & line_bitmasks[3]) == line_bitmasks[3]) continue;
		if ((set & line_bitmasks[4]) == line_bitmasks[4]) continue;
		if ((set & line_bitmasks[5]) == line_bitmasks[5]) continue;
		if ((set & line_bitmasks[6]) == line_bitmasks[6]) continue;
		if ((set & line_bitmasks[7]) == line_bitmasks[7]) continue;
		if ((set & line_bitmasks[8]) == line_bitmasks[8]) continue;
		if ((set & line_bitmasks[9]) == line_bitmasks[9]) continue;
		if ((set & line_bitmasks[10]) == line_bitmasks[10]) continue;
		if ((set & line_bitmasks[11]) == line_bitmasks[11]) continue;
		if ((set & line_bitmasks[12]) == line_bitmasks[12]) continue;
		if ((set & line_bitmasks[13]) == line_bitmasks[13]) continue;
		if ((set & line_bitmasks[14]) == line_bitmasks[14]) continue;
		if ((set & line_bitmasks[15]) == line_bitmasks[15]) continue;
		if ((set & line_bitmasks[16]) == line_bitmasks[16]) continue;
		if ((set & line_bitmasks[17]) == line_bitmasks[17]) continue;
		if ((set & line_bitmasks[18]) == line_bitmasks[18]) continue;
		if ((set & line_bitmasks[19]) == line_bitmasks[19]) continue;
		if ((set & line_bitmasks[20]) == line_bitmasks[20]) continue;
		if ((set & line_bitmasks[21]) == line_bitmasks[21]) continue;
		if ((set & line_bitmasks[22]) == line_bitmasks[22]) continue;
		if ((set & line_bitmasks[23]) == line_bitmasks[23]) continue;
		if ((set & line_bitmasks[24]) == line_bitmasks[24]) continue;
		if ((set & line_bitmasks[25]) == line_bitmasks[25]) continue;
		if ((set & line_bitmasks[26]) == line_bitmasks[26]) continue;
		if ((set & line_bitmasks[27]) == line_bitmasks[27]) continue;
		if ((set & line_bitmasks[28]) == line_bitmasks[28]) continue;
		if ((set & line_bitmasks[29]) == line_bitmasks[29]) continue;
		if ((set & line_bitmasks[30]) == line_bitmasks[30]) continue;
 		if ((set & line_bitmasks[31]) == line_bitmasks[31]) continue;
		if ((set & line_bitmasks[32]) == line_bitmasks[32]) continue;
		if ((set & line_bitmasks[33]) == line_bitmasks[33]) continue;
		if ((set & line_bitmasks[34]) == line_bitmasks[34]) continue;
		if ((set & line_bitmasks[35]) == line_bitmasks[35]) continue;
		if ((set & line_bitmasks[36]) == line_bitmasks[36]) continue;
		if ((set & line_bitmasks[37]) == line_bitmasks[37]) continue;
		if ((set & line_bitmasks[38]) == line_bitmasks[38]) continue;
		if ((set & line_bitmasks[39]) == line_bitmasks[39]) continue;
		if ((set & line_bitmasks[40]) == line_bitmasks[40]) continue;
		if ((set & line_bitmasks[41]) == line_bitmasks[41]) continue;
		if ((set & line_bitmasks[42]) == line_bitmasks[42]) continue;
		if ((set & line_bitmasks[43]) == line_bitmasks[43]) continue;
		if ((set & line_bitmasks[44]) == line_bitmasks[44]) continue;
		if ((set & line_bitmasks[45]) == line_bitmasks[45]) continue;
		if ((set & line_bitmasks[46]) == line_bitmasks[46]) continue;
		if ((set & line_bitmasks[47]) == line_bitmasks[47]) continue;
		if ((set & line_bitmasks[48]) == line_bitmasks[48]) continue;
/* We have a line-free set! */
				/* now compute the a,b,c,d stats */
				s[0]=s[1]=s[2]=s[3]=0;
			      tmpset = set;
				for (j=0; j < 27; j++)
					{
						if (tmpset & 1l) s[stat[j]]++;
						tmpset /= 2;
					}
           		numstat[s[0]][s[1]][s[2]][s[3]]++;
			num_linefree++;
		}




count=0;
for (a=0; a<9; a++)
	for (b=0; b<13; b++)
		for (c=0; c<7; c++)
			for (d=0; d<2; d++)
				if (numstat[a][b][c][d] > 0)
					{
						count++;
				 		printf("%ld sets with stats (%d,%d,%d,%d)\n",numstat[a][b][c][d],a,b,c,d);
					}
printf("%ld line-free sets total, with %d different stats?\n",num_linefree,count);
}