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