I'll be heading on out now...

[ Follow Ups ] [ Post Followup ] [ Main Message Board ] [ FAQ ]

Posted by Joel on October 28, 2002 at 18:36:17:

In Reply to: to keep Joel (or anybody who wants to try this) off the streets! posted by Denis Borris on October 28, 2002 at 02:48:27:

: Magic Triangle:
: Take the 15 pool balls (numbers 01 to 15) and a pool triangle and
: arrange the balls such that every ball number in the upper 4 rows
: is the difference between the numbers of the two balls directly below.

Did my mother tell you I need to be kept off the streets?

` 6   14   15    3    13   8    1    12   10      7   11    2        4    9          5(and the reverse, of course)The code is pretty repetitious.  You can probably find a simpler way, although mine does get the answer instantly.#include #include #include main(){        int y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,setA[15],setB[15],setC[14],setD[13],setE[12];        int setF[11],setG[10],setH[9],setI[8],setJ[7],setK[6],setL[5],setM[4],setN[3],rack[15];        for (z=0;z<15;z++)            setA[z]=z+1;        for (a=0;a<15;a++)        {   rack[0]=setA[a];                        //pick ball 1            for(z=0;z<15;z++)                setB[z]=setA[z];                    //make copy of set            setB[a]=setB[14];                   //make it smaller (14)                        for(b=0;b<14;b++)            {   rack[1]=setB[b];                    //pick ball 2                for(z=0;z<14;z++)                    setC[z]=setB[z];                //make copy of set                setC[b]=setC[13];               //make it smaller (13)                                for(c=0;c<13;c++)                {   rack[2]=setC[c];                //pick ball 3                    for(z=0;z<13;z++)                        setD[z]=setC[z];            //make copy of set                    setD[c]=setD[12];           //make it smaller (12)                                        for(d=0;d<12;d++)                    {   rack[3]=setD[d];            //pick ball 4                        for(z=0;z<12;z++)                            setE[z]=setD[z];        //make copy of set                        setE[d]=setE[11];       //make it smaller (11)                                                for(e=0;e<11;e++)                        {   rack[4]=setE[e];        //pick ball 5                            for(z=0;z<11;z++)                                setF[z]=setE[z];    //make copy of set                            setF[e]=setF[10];   //make it smaller (10)                                                        for(f=0;f<10;f++)                            { rack[5]=setF[f];                    //pick ball 6                              if(rack[5]==abs(rack[0]-rack[1]))                                                                    //if it works                              {for(z=0;z<10;z++)                                setG[z]=setF[z];                //make copy of set                              setG[f]=setG[9];                //make it smaller (9)                                                              for(g=0;g<9;g++)                              { rack[6]=setG[g];                //pick ball 7                                if(rack[6]==abs(rack[1]-rack[2]))                                                                    //if it works                                {for(z=0;z<9;z++)                                    setH[z]=setG[z];                //make copy of set                                  setH[g]=setH[8];                //make it smaller (8)                                                            for(h=0;h<8;h++)                                { rack[7]=setH[h];                //pick ball 8                                  if(rack[7]==abs(rack[2]-rack[3]))                                                                //if it works                                  {for(z=0;z<8;z++)                                    setI[z]=setH[z];                //make copy of set                                  setI[h]=setI[7];                //make it smaller (7)                                                              for(i=0;i<7;i++)                                  { rack[8]=setI[i];                //pick ball 9                                    if(rack[8]==abs(rack[3]-rack[4]))                                                                //if it works                                    {for(z=0;z<7;z++)                                      setJ[z]=setI[z];                //make copy of set                                    setJ[i]=setJ[6];                //make it smaller (6)                                                                for(j=0;j<6;j++)                                    { rack[9]=setJ[j];                //pick ball 10                                      if(rack[9]==abs(rack[5]-rack[6]))                                                                //if it works                                      {for(z=0;z<6;z++)                                        setK[z]=setJ[z];                //make copy of set                                      setK[j]=setK[5];                //make it smaller (5)                                                                for(k=0;k<5;k++)                                      { rack[10]=setK[k];               //pick ball 11                                        if(rack[10]==abs(rack[6]-rack[7]))                                                                //if it works                                        {for(z=0;z<5;z++)                                          setL[z]=setK[z];                  //make copy of set                                        setL[k]=setL[4];                    //make it smaller (4)                                                                    for(l=0;l<4;l++)                                        { rack[11]=setL[l];                 //pick ball 12                                          if(rack[11]==abs(rack[7]-rack[8]))                                                                            //if it works                                          {for(z=0;z<4;z++)                                            setM[z]=setL[z];                //make copy of set                                          setM[l]=setM[3];                  //make it smaller (3)                                                                      for(m=0;m<3;m++)                                          { rack[12]=setM[m];               //pick ball 13                                            if(rack[12]==abs(rack[9]-rack[10]))                                                                            //if it works                                            {for(z=0;z<3;z++)                                              setN[z]=setM[z];              //make copy of set                                            setN[m]=setN[2];                //make it smaller (2)                                                                        rack[13]=setN[0];               //pick last 2 balls                                            rack[14]=setN[1];                                            if(rack[13]==abs(rack[10]-rack[11]) &&                                                 rack[14]==abs(rack[12]-rack[13]))                                                                                        {  cout << "eureka" << endl;                                               for (y=0;y<15;y++)                                                 cout << "ball " << y+1 << ": " << rack[y] << endl;                                               getchar();                                            }                                            rack[13]=setN[1];               //reverse the last 2 balls                                            rack[14]=setN[0];                                            if(rack[13]==abs(rack[10]-rack[11]) &&                                                rack[14]==abs(rack[12]-rack[13]))                                            { cout << "eureka" << endl;                                              for (y=0;y<15;y++)                                                cout << "ball " << y+1 << ": " << rack[y] << endl;                                              getchar();                                            }                        }}}}}}}}}}}}}}}}}}}}} }`

Name:
E-Mail:

Subject: