# Re: Well, I'll be damned...(even better!)

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

Posted by Joel on October 12, 2002 at 12:36:14:

In Reply to: Re: Well, I'll be damned... posted by Denis Borris on October 12, 2002 at 00:12:11:

: : There's actually two of 'em:

: : 1+6+7+17+18+23 = 2+3+11+13+21+22
: : 2+7+8+18+19+24 = 3+4+12+14+22+23

: Yep; actually, the "basic or native" solution is the 1st one;
: if you increase the limit to 25, you'll also get:
: 3+8+9+19+20+25 = 4+5+13+15+23+ 24
: ....and so on infinitely!

:
: : Takes my pc just under 10 seconds to get the first one, another 14 seconds
: : to the next, and about 38 seconds to finish.

: Wow! Takes mine a bit over 2 minutes (old 486!).
: Your "looping" sure beats mine, then.
: What does your looping look like, from g to k ? (I calculate L).

I wasn't completely satisfied with that one, so I cleaned it up a bit more. With the new, improved version, lap (11 6 7 17 18 23 / 2 3 11 13 21 22) is 5.06 seconds, lap 2 (2 7 8 18 19 24 / 3 4 12 14 22 23 6.44 seconds, lap 3 (just finishing up) 7.99 seconds. Total 19.49 seconds. Saved a few years. :)

Here's the code. Sorry, it's in C++. If anything's not clear, just ask. Hopefully, I put in enough extra spaces so my < 's don't get interpreted as HTML tags by the message board program. Otherwise I'll just try, try again.

#include < iostream.h> // that's just boilerplate for i/o functions

int main()
{
int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,sum,sum2=0,lh[24];

// just keep in mind that in C the convention
// is to start counting at 0, not 1

for(m=0;m< 19;m++)
{a=m+1;
for(n=a;n< 20;n++)
{b=n+1;
for(o=b;o< 21;o++)
{c=o+1;
for(p=c;p< 22;p++)
{d=p+1;
for(q=d;q< 23;q++)
{e=q+1;
for(r=e;r< 24;r++)
if((sum=a+b+c+d+e+r+1)< 112)
{f=r+1;

// The lh[] array records the numbers chosen for
// a through f. This loop initializes it to 0.
for(y=0;y< 24;y++)
lh[y]=0;

// Now store a - f for this iteration. C arrays

lh[a-1]=1;lh[b-1]=1;lh[c-1]=1;lh[d-1]=1;lh[e-1]=1;lh[f-1]=1;

// start looping g where a left off - no need
// to have g-l duplicate a-f
// also, if sum2 (g through l) is greater than

for(s=a,sum2=0;s< 19&&!(sum2>sum);s++)
if(!lh[s])
{g=s+1;
for(t=g;t< 20;t++)
if(!lh[t])
{h=t+1;
for(u=h;u< 21;u++)
if(!lh[u])
{i=u+1;
for(v=i;v< 22;v++)
if(!lh[v])
{j=v+1;
for(w=j;w< 23;w++)
if(!lh[w])
{k=w+1;
for(x=k,sum2=0;x< 24&&!(sum2>sum);x++)
{sum2=g+h+i+j+k+x+1;
if(!lh[x])
{l=x+1;
if(sum2==sum)
if(a*a+b*b+c*c+d*d+e*e+f*f==g*g+h*h+i*i+j*j+k*k+l*l)
if(a*a*a+b*b*b+c*c*c+d*d*d+e*e*e+f*f*f
==g*g*g+h*h*h+i*i*i+j*j*j+k*k*k+l*l*l)
if(a*a*a*a+b*b*b*b+c*c*c*c+d*d*d*d+e*e*e*e+f*f*f*f
==g*g*g*g+h*h*h*h+i*i*i*i+j*j*j*j+k*k*k*k+l*l*l*l)
if(a*a*a*a*a+b*b*b*b*b+c*c*c*c*c+d*d*d*d*d+e*e*e*e*e
+f*f*f*f*f==g*g*g*g*g+h*h*h*h*h+i*i*i*i*i+j*j*j*j*j
+k*k*k*k*k+l*l*l*l*l)
{ cout < < a < < " " < < b < < " " < < c < < " " < < d
<< " " << e < < " " < < f < < endl;
cout < < g << " " < < h < < " " < < i < < " " < < j
< < " " < < k < < " " < < l < < endl;
}
}}}}}}}}}}}}}

return 0;
}

Name:
E-Mail:

Subject: