FANDOM


This is my C program for solving BEAF's linar arrays!

int solve_linear_array(int array[], int size)
{
        assert(size >= 0 && array);

        if (size == 0) {
                return 1;
        }

        /*
         * "what if he gives you an array smaller than what "size" says it is?"
         * world peace happen. (and the program crashes, of course)
         */


        /* {a} = a; */
        if (size == 1) {
                return array[0];
        }

        if (size == 2) {
                while (array[1]--) {
                        array[0] *= array[0];
                }
                return array[0];
        }

        int i, j;
        for (i = 2 ; i < size && array[i] == 1 ; i++);
        for (j = 2 ; j < i ; j++) { array[j] = array[0]; }

        int *narray = calloc(size, sizeof(int));

        /* new array {a,b-1,...} */
        memcpy(&narray, array, size);

        /* decrease prime */
        --narray[1];

        array[i]--;
        array[i-1] = solve_linear_array(narray, size);


        while (array[size - 1] == 1) {
                --size;
        }

        return solve_linear_array(array, size);
}

int linear_array_of(int x, int size)
{
        int i;
        int *array = calloc(size, 1);

        for (i = 0 ; i < size ; i++) { array[i] = x; }

        return solve_linear_array(array, size);
}


#define TRITRI (linear_array_of(3,3))
#define TRITET (linear_array_of(4,3))
#define TRIPENT (linear_array_of(5,3))
#define TRIHEX (linear_array_of(6,3))
#define TRISEPT (linear_array_of(7,3))
#define TRIOCT (linear_array_of(8,3))
#define TRININE (linear_array_of(9,3))
#define TRIDECAL (linear_array_of(10,3))

#define linear_array_3(a,b,c) ({ int *_array=calloc(3,sizeof(int)); \
        _array[0]=a;_array[1]=b;_array[2]=c; \
        (solve_linear_array(_array,3));})
#define linear_array_4(a,b,c,d) ({ int *_array=calloc(4,sizeof(int)); \
        _array[0]=a;_array[1]=b;_array[2]=c;_array[3]=d; \
        (solve_linear_array(_array,4));})
#define linear_array_5(a,b,c,d,e) ({ int *_array=calloc(5,sizeof(int)); \
        _array[0]=a;_array[1]=b;_array[2]=c;_array[3]=d;_array[4]=e; \
        (solve_linear_array(_array,5));})
#define linear_array_6(a,b,c,d,e,f) ({ int *_array=calloc(6,sizeof(int)); \
        _array[0]=a;_array[1]=b;_array[2]=c;_array[3]=d; \
        _array[4]=e;_array[5]=f; \
        (solve_linear_array(_array,6));})
#define linear_array_7(a,b,c,d,e,f,g) ({ int *_array=calloc(7,sizeof(int)); \
        _array[0]=a;_array[1]=b;_array[2]=c;_array[3]=d; \
        _array[4]=e;_array[5]=f;_array[6]=g; \
        (solve_linear_array(_array,7));})
#define linear_array_8(a,b,c,d,e,f,g,h) ({ int *_array=calloc(8,sizeof(int)); \
        _array[0]=a;_array[1]=b;_array[2]=c;_array[3]=d; \
        _array[4]=e;_array[5]=f;_array[6]=g;_array[7]=h; \
        (solve_linear_array(_array,8));})
#define linear_array_9(a,b,c,d,e,f,g,h,i) ({ int *_array=calloc(9,sizeof(int)); \
        _array[0]=a;_array[1]=b;_array[2]=c;_array[3]=d; \
        _array[4]=e;_array[5]=f;_array[6]=g;_array[7]=h;_array[8]=i; \
        (solve_linear_array(_array,9));})
#define linear_array_10(a,b,c,d,e,f,g,h,i,j) ({ int *_array=calloc(10,sizeof(int)); \
        _array[0]=a;_array[1]=b;_array[2]=c;_array[3]=d; \
        _array[4]=e;_array[5]=f;_array[6]=g;_array[7]=h; \
        _array[8]=i;_array[9]=j; \
        (solve_linear_array(_array,10));})
#define linear_array_11(a,b,c,d,e,f,g,h,i,j,k) ({ int *_array=calloc(11,sizeof(int)); \
        _array[0]=a;_array[1]=b;_array[2]=c;_array[3]=d; \
        _array[4]=e;_array[5]=f;_array[6]=g;_array[7]=h; \
        _array[8]=i;_array[9]=j;_array[10]=k; \
        (solve_linear_array(_array,11));})
#define linear_array_12(a,b,c,d,e,f,g,h,i,j,k,l) ({ int *_array=calloc(12,sizeof(int)); \
        _array[0]=a;_array[1]=b;_array[2]=c;_array[3]=d; \
        _array[4]=e;_array[5]=f;_array[6]=g;_array[7]=h; \
        _array[8]=i;_array[9]=j;_array[10]=k;_array[11]=l; \
        (solve_linear_array(_array,12));})

#define EXPANSION(a,b) linear_array_4(a,b,1,2)
#define MULTIEXPANSION(a,b) linear_array_4(a,b,2,2)
#define POWEREXPANSION(a,b) linear_array_4(a,b,3,2)
#define EXPANDOTETRATION(a,b) linear_array_4(a,b,4,2)
#define EXPLOSION(a,b) linear_array_4(a,b,1,3)
#define MULTIEXPLOSION(a,b) linear_array_4(a,b,2,3)
#define POWEREXPLOSION(a,b) linear_array_4(a,b,3,3)
#define EXPLODOTETRATION(a,b) linear_array_4(a,b,4,3)
#define DETONATION(a,b) linear_array_4(a,b,1,4)
#define PENTONATION(a,b) linear_array_4(a,b,1,5)
#define HEXONATION(a,b) linear_array_4(a,b,1,6)
#define HEPTONATION(a,b) linear_array_4(a,b,1,7)
#define OCTONATION(a,b) linear_array_4(a,b,1,8)
#define ENNONATION(a,b) linear_array_4(a,b,1,9)
#define DECONATION(a,b) linear_array_4(a,b,1,10)
#define MEGOTION(a,b) linear_array_4(a,b,1,1,2)
#define MULTIMEGOTION(a,b) linear_array_4(a,b,2,1,2)
#define POWERMEGOTION(a,b) linear_array_4(a,b,3,1,2)
#define MEGOTETRATION(a,b) linear_array_4(a,b,4,1,2)
#define MEGOEXPANSION(a,b) linear_array_4(a,b,1,2,2)
#define MULTIMEGOEXPANSION(a,b) linear_array_4(a,b,2,2,2)
#define POWERMEGOEXPANSION(a,b) linear_array_4(a,b,3,2,2)
#define MEGOEXPANDOTETRATION(a,b) linear_array_4(a,b,4,2,2)
#define MEGOEXPLOSION(a,b) linear_array_4(a,b,1,3,2)
#define MEGODETONATION(a,b) linear_array_4(a,b,1,4,2)
#define GIGOTION(a,b) linear_array_4(a,b,1,1,3)
#define GIGOEXPANTION(a,b) linear_array_4(a,b,1,2,3)
#define GIGOEXPLOSION(a,b) linear_array_4(a,b,1,3,3)
#define GIGODETONATION(a,b) linear_array_4(a,b,1,4,3)
#define TEROTION(a,b) linear_array_4(a,b,1,1,4)
#define PETOTION(a,b) linear_array_4(a,b,1,1,5)
#define HATOTION(a,b) linear_array_4(a,b,1,1,6)
#define HEPOTION(a,b) linear_array_4(a,b,1,1,7)
#define OCOTION(a,b) linear_array_4(a,b,1,1,8)
#define NANOTION(a,b) linear_array_4(a,b,1,1,9)
#define UZOTION(a,b) linear_array_4(a,b,1,1,10)
#define UUOTION(a,b) linear_array_4(a,b,1,1,11)
#define UDOTION(a,b) linear_array_4(a,b,1,1,12)
#define UTOTION(a,b) linear_array_4(a,b,1,1,13)
#define UEOTION(a,b) linear_array_4(a,b,1,1,14)
#define UPOTION(a,b) linear_array_4(a,b,1,1,15)
#define UHOTION(a,b) linear_array_4(a,b,1,1,16)
#define UAOTION(a,b) linear_array_4(a,b,1,1,17)
#define UOOTION(a,b) linear_array_4(a,b,1,1,18)
#define UNOTION(a,b) linear_array_4(a,b,1,1,19)
#define DZOTION(a,b) linear_array_4(a,b,1,1,20)
#define TZOTION(a,b) linear_array_4(a,b,1,1,30)
#define UZZOTION(a,b) linear_array_4(a,b,1,1,100)

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.