#include #include #include using namespace std; void possible(int); void viable(int); void solutions(int); int main() { cout << endl; cout << "This program enumerates all possible restricted and" << endl; cout << "unrestricted Sarvate-Beam quad systems with v=6." << endl; for(int s= 4; s<= 9; s++) { possible(s); viable(s); solutions(s); } cout << endl; cout << "Solutions are stored in u64solns.dat" << endl; cout << endl; return(0); } void possible(int y) { int i,j,k,m,n,z= 19-y; ofstream output1,output2; output1.open("apossible.dat"); for(i= 0; i<= y; i++) for(j= 0; j<= y; j++) for(k= 0; k<= y; k++) for(m= 0; m<= y; m++) if(i+ j+ k+ m== y) output1 << i << " " << j << " " << k << " " << m << endl; output1.close(); output2.open("bpossible.dat"); for(i= 0; i<= z; i++) for(j= 0; j<= z; j++) for(k= 0; k<= z; k++) for(m= 0; m<= z; m++) for(n= 0; n<= z; n++) if(i+ j+ k+ m+ n== z) output2 << i << " " << j << " " << k << " " << m << " " << n << endl; output2.close(); } void viable(int y) { int inp[5],a[4],i,j,v,z= 19-y; ifstream input1,input2; ofstream output1,output2; input1.open("apossible.dat"); output1.open("aviable.dat"); input1 >> inp[0] >> inp[1] >> inp[2] >> inp[3]; while(! input1.eof()) { a[0]= inp[0]+ inp[1]+ inp[2]+ 1; a[1]= inp[0]+ inp[1]+ inp[3]+ 1; a[2]= inp[0]+ inp[2]+ inp[3]; a[3]= inp[1]+ inp[2]+ inp[3]; v= 0; for(i= 0; i<= 2; ++i) for(j= i+ 1; j<= 3; ++j) if(a[i]==a[j] || a[i]<2 || a[i]>15 || a[j]<2 || a[j]>15) v+= 1; switch(v) { case 0: output1 << inp[0] << " " << inp[1] << " " << inp[2] << " " << inp[3] << endl; break; default: ; } input1 >> inp[0] >> inp[1] >> inp[2] >> inp[3]; } input1.close(); output1.close(); input2.open("bpossible.dat"); output2.open("bviable.dat"); input2 >> inp[0] >> inp[1] >> inp[2] >> inp[3] >> inp[4]; while(! input2.eof()) { a[0]= inp[0]+ inp[1]+ inp[2]+ 1; a[1]= inp[0]+ inp[1]+ inp[3]+ 1; a[2]= inp[0]+ inp[2]+ inp[3]; a[3]= inp[1]+ inp[2]+ inp[3]; v= 0; for(i= 0; i<= 2; ++i) for(j= i+ 1; j<= 3; ++j) if(a[i]==a[j] || a[i]<2 || a[i]>15 || a[j]<2 || a[j]>15) v+= 1; switch(v) { case 0: output2 << inp[0] << " " << inp[1] << " " << inp[2] << " " << inp[3] << " " << inp[4] << endl; break; default: ; } input2 >> inp[0] >> inp[1] >> inp[2] >> inp[3] >> inp[4]; } input2.close(); output2.close(); } void solutions(int y) { int inp1[4],inp2[5],c[14],i,j,v,z= 19-y; ifstream input1,input2; ofstream output1; input1.open("aviable.dat"); input2.open("bviable.dat"); output1.open("u64solns.dat", ios::app ); input1 >> inp1[0] >> inp1[1] >> inp1[2] >> inp1[3]; input2 >> inp2[0] >> inp2[1] >> inp2[2] >> inp2[3] >> inp2[4]; do { do { c[0]= inp1[0]+ inp1[1]+ inp1[2]+ 1; c[1]= inp1[0]+ inp1[1]+ inp1[3]+ 1; c[2]= inp1[0]+ inp1[2]+ inp1[3]; c[3]= inp1[1]+ inp1[2]+ inp1[3]; c[4]= inp2[0]+ inp2[1]+ inp2[2]+ 1; c[5]= inp2[0]+ inp2[1]+ inp2[3]+ 1; c[6]= inp2[0]+ inp2[2]+ inp2[3]; c[7]= inp2[1]+ inp2[2]+ inp2[3]; c[8]= inp1[0]+ inp1[1]+ inp2[0]+ inp2[1]+ inp2[4]+ 1; c[9]= inp1[0]+ inp1[2]+ inp2[0]+ inp2[2]+ inp2[4]; c[10]= inp1[1]+ inp1[2]+ inp2[1]+ inp2[2]+ inp2[4]; c[11]= inp1[0]+ inp1[3]+ inp2[0]+ inp2[3]+ inp2[4]; c[12]= inp1[1]+ inp1[3]+ inp2[1]+ inp2[3]+ inp2[4]; c[13]= inp1[2]+ inp1[3]+ inp2[2]+ inp2[3]+ inp2[4]; v= 0; for(i= 0; i<13; ++i) { for(j= i+ 1; j<14; ++j) { if(c[i]==c[j] || c[i]<2 || c[i]>15 || c[j]<2 || c[j]>15) v+= 1; } } switch(v) { case 0: output1 << "1 " << inp1[0] << " " << inp1[1] << " " << inp1[2] << " " << inp1[3] << " " << inp2[0] << " " << inp2[1] << " " << inp2[2] << " " << inp2[3] << " " << inp2[4] << endl; break; default: ; } input2 >> inp2[0] >> inp2[1] >> inp2[2] >> inp2[3] >> inp2[4]; } while(! input2.eof()); input2.close(); input2.open("bviable.dat"); input2 >> inp2[0] >> inp2[1] >> inp2[2] >> inp2[3] >> inp2[4]; input1 >> inp1[0] >> inp1[1] >> inp1[2] >> inp1[3]; } while(! input1.eof()); input1.close(); input2.close(); output1.close(); }