[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[at-l] HELP, I'M SO DANGED CORNFUSED! (WAY OT)



There are actually 288 solutions to this problem. :-)

Here's my contribution to the homework, the worlds most poorly written C
program (don't worry- the stuff that runs the lists is better :-)

#include <stdio.h>

main()
{
int x,y,z;    /* Vertex Numbers */
int a,b,c,d,e,f;   /*   Line Numbers */
int solutions;

solutions=0;

/* Triangle looks like this */
/*        X      */
/*       A E     */
/*      B   F    */
/*     Y C D Z   */

/* Yes, I could do this with an array, but why not just brute force it? */
/* Why be cool? */

for(x=1;x<=9;x++) {
for(y=1;y<=9;y++) {
for(z=1;z<=9;z++) {
for(a=1;a<=9;a++) {
for(b=1;b<=9;b++) {
for(c=1;c<=9;c++) {
for(d=1;d<=9;d++) {
for(e=1;e<=9;e++) {
for(f=1;f<=9;f++) {

/* Hahaha... the above just cracks me up */

if(
        x!=y && x!=z && x!=a && x!=b && x!=c && x!=d && x!=e && x!=f &&
        y!=x && y!=z && y!=a && y!=b && y!=c && y!=d && y!=e && y!=f &&
        z!=y && z!=x && z!=a && z!=b && z!=c && z!=d && z!=e && z!=f &&
        a!=x && a!=y && a!=z && a!=b && a!=c && a!=d && a!=e && a!=f &&
        b!=x && b!=y && b!=z && b!=a && b!=c && b!=d && b!=e && b!=f &&
        c!=x && c!=y && c!=z && c!=a && c!=b && c!=d && c!=e && c!=f &&
        d!=x && d!=y && d!=z && d!=a && d!=b && d!=c && d!=e && d!=f &&
        e!=x && e!=y && e!=z && e!=a && e!=b && e!=c && e!=f && e!=d &&
        f!=x && f!=y && f!=z && f!=a && f!=b && f!=c && f!=d && f!=e ) {

                /* Okay, that was even funnier, since I checked em all
twice.. */
                /* See, that was more fun that using an array :-) */
                /* dumb, dumber, dumbest */

                if((a+b+c+d+e+f+x+y+z)!=(1+2+3+4+5+6+7+8+9)) {
                        printf("I've lost my mind.\n");
                        exit(0);
                }

                if( (x+a+b+y)==20 && (y+c+d+z)==20 && (x+e+f+z)==20) {
                        printf("\nWe have a winner!\n\n");
                        printf("       %d    \n",x);
                        printf("      %d %d   \n",a,e);
                        printf("     %d   %d  \n",b,f);
                        printf("    %d %d %d %d \n\n",y,c,d,z);
                        solutions++;
                }

        }

} } } } } } } }

printf("%i%% complete...\n",x*10);

}

printf("\n 100%% complete. %d solutions found. Go work on the archives
now.\n",solutions);
exit(0);

}

/* This was the most inefficient program I've ever written, yet somehow more
interesting than guns on the trail */


----- Original Message -----
From: "Rami" <rbenhameda@home.com>
To: <at-L@backcountry.net>
Sent: Friday, February 01, 2002 5:19 PM
Subject: [at-l] HELP, I'M SO DANGED CORNFUSED! (WAY OT)


> Help you guys.  I don't think my brain can handle this any more...
>