Guyz. Im in a competition. Please help me solve this. I need to code a program to solve this. I dont know where to start. Can anyone setup a recurrence relation?
please

On an island chameleons of different color live.

Every Monday , the following events occur

The number of Black chameleons born is 1000 more than sum of { existing Blue , existing Green and twice the existing White chameleons }

The number of Brown chameleons becomes 13 more than twice the existing Brown

The number of Red chameleons triples

All the Yellow chameleons change their color to Black
Every Tuesday , the following events occur

The number of Yellow chameleons born is 1000 more than sum of { existing Black , existing Red and twice the existing Brown chameleons }

The number of Blue chameleons becomes 13 more than twice the existing Blue

The number of White chameleons triples

All the Green chameleons change their color to Yellow

Every Wednesday , the following events occur

The number of Green chameleons born is 1000 more than sum of { existing Yellow , existing White and twice the existing Blue chameleons }

The number of Black chameleons becomes 13 more than twice the existing Black

The number of Brown chameleons triples

All the Red chameleons change their color to Green

Every Thursday , the following events occur

The number of Red chameleons born is 1000 more than sum of { existing Green , existing Brown and twice the existing Black chameleons }

The number of Yellow chameleons becomes 13 more than twice the existing Yellow

The number of Blue chameleons triples

All the White chameleons change their color to Red

Every Friday , the following events occur

The number of White chameleons born is 1000 more than sum of { existing Red , existing Blue and twice the existing Yellow chameleons }

The number of Green chameleons becomes 13 more than twice the existing Green

The number of Black chameleons triples

All the Brown chameleons change their color to White

Every Saturday , the following events occur

The number of Brown chameleons born is 1000 more than sum of { existing White , existing Black and twice the existing Green chameleons }

The number of Red chameleons becomes 13 more than twice the existing Red

The number of Yellow chameleons triples

All the Blue chameleons change their color to Brown

Every Sunday , the following events occur

The number of Blue chameleons born is 1000 more than sum of { existing Brown , existing Yellow and twice the existing Red chameleons }

The number of White chameleons becomes 13 more than twice the existing White

The number of Green chameleons triples

All the Black chameleons change their color to Blue

On the same island there lives a monster . Whenever he sees 10^7 chameleons of the same color he eats them all immediately . How many chameleons change their color on the 3rd day after the 10^17th week . Initially there are no chameleons on the island . The first day is a Monday .

Comments
don't think you should be in this competition

monday.txt

8,8
0,1,1,2,0,0,1,1000
0,1,0,0,0,0,0,0
0,0,1,0,0,0,0,0
0,0,0,1,0,0,0,0
0,0,0,0,2,0,0,13
0,0,0,0,0,3,0,0
0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,1

tuesday.txt

8,8
1,0,0,0,0,0,0,0
0,2,0,0,0,0,0,13
0,0,0,0,0,0,0,0
0,0,0,3,0,0,0,0
0,0,0,0,1,0,0,0
0,0,0,0,0,1,0,0
1,0,1,0,2,1,0,1000
0,0,0,0,0,0,0,1

wednesday.txt

8,8
2,0,0,0,0,0,0,13
0,1,0,0,0,0,0,0
0,2,0,1,0,1,1,1000
0,0,0,1,0,0,0,0
0,0,0,0,3,0,0,0
0,0,0,0,0,0,0,0
0,0,0,0,0,0,1,0
0,0,0,0,0,0,0,1

thursday.txt

8,8
1,0,0,0,0,0,0,0
0,3,0,0,0,0,0,0
0,0,1,0,0,0,0,0
0,0,0,0,0,0,0,0
0,0,0,0,1,0,0,0
2,0,1,1,1,0,0,1000
0,0,0,0,0,0,2,13
0,0,0,0,0,0,0,1

friday.txt

8,8
3,0,0,0,0,0,0,0
0,1,0,0,0,0,0,0
0,0,2,0,0,0,0,13
0,1,0,0,1,1,2,1000
0,0,0,0,0,0,0,0
0,0,0,0,0,1,0,0
0,0,0,0,0,0,1,0
0,0,0,0,0,0,0,1

saturday.txt

8,8
1,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0
0,0,1,0,0,0,0,0
0,0,0,1,0,0,0,0
1,1,2,1,0,0,0,1000
0,0,0,0,0,2,0,13
0,0,0,0,0,0,3,0
0,0,0,0,0,0,0,1

sunday.txt

8,8
0,0,0,0,0,0,0,0
1,0,0,0,1,2,1,1000
0,0,3,0,0,0,0,0
0,0,0,2,0,0,0,13
0,0,0,0,1,0,0,0
0,0,0,0,0,1,0,0
0,0,0,0,0,0,1,0
0,0,0,0,0,0,0,1

finalize.txt

1,8
0
0
0
0
0
0
0
1
#include <stdio.h>
#include <stdlib.h>

struct MiniMatrix {
    int cols, rows;
    int vals[8][8];
};

int parsematrix(struct MiniMatrix* dest, char* filename) {
    int i, j;
    char end;
    FILE* in = fopen(filename, "r");

    if(in == NULL) {
        return 1;
    }

    fscanf(in, "%d,%d\n", &dest->cols, &dest->rows);

    for(i = 0; i < dest->rows; i++) {
        for(j = 0; j < dest->cols; j++) {
            fscanf(in, "%d%c", &dest->vals[i][j], &end);
        }
    }
    fclose(in);

    return 0;
}

int outputmatrix(struct MiniMatrix* src, char* filename) {
    int i, j;
    FILE* out = fopen(filename, "w");

    if(out == NULL) {
        return 1;
    }

    fprintf(out, "%d,%d\n", src->cols, src->rows);

    for(i = 0; i < src->rows; i++) {
        for(j = 0; j < src->cols; j++) {
            fprintf(out, "%d", src->vals[i][j]);

            if(j < src->cols-1) {
                fprintf(out, ",");
            }
        }
        fprintf(out, "\n");
    }

    fclose(out);

    return 0;
}

int multmatrix(struct MiniMatrix* c, struct MiniMatrix* a, struct MiniMatrix* b) {
    int i, j, k;

    if(a->cols != b->rows) {
        return 1;
    }

    c->cols = b->cols;
    c->rows = a->rows;

    for(i = 0; i < a->rows; i++) {
        for(j = 0; j < b->cols; j++) {
            c->vals[i][j] = 0;

            for(k = 0; k < a->cols; k++) {
                c->vals[i][j] += (int)((((long long)a->vals[i][k])*((long long)b->vals[k][j]))%10000000LL);
            }
        }
    }

    return 0;
}

int main() {
    struct MiniMatrix res1, res2, res3;

    parsematrix(&res1, "monday.txt");
    parsematrix(&res3, "tuesday.txt");
    multmatrix(&res2, &res1, &res3);
    parsematrix(&res3, "wednesday.txt");
    multmatrix(&res1, &res2, &res3);
    parsematrix(&res3, "thursday.txt");
    multmatrix(&res2, &res1, &res3);
    parsematrix(&res3, "friday.txt");
    multmatrix(&res1, &res2, &res3);
    parsematrix(&res3, "saturday.txt");
    multmatrix(&res2, &res1, &res3);
    parsematrix(&res3, "sunday.txt");
    multmatrix(&res1, &res2, &res3); //one week??


    multmatrix(&res2, &res1, &res1);
    multmatrix(&res3, &res2, &res2);
    multmatrix(&res2, &res3, &res3);
    multmatrix(&res3, &res2, &res1);
    multmatrix(&res2, &res3, &res1);//raised to 10

    multmatrix(&res2, &res1, &res1);
    multmatrix(&res3, &res2, &res2);
    multmatrix(&res2, &res3, &res3);
    multmatrix(&res3, &res2, &res2);
    multmatrix(&res2, &res3, &res1); //raised to 7

    parsematrix(&res1, "monday.txt");
    multmatrix(&res3, &res2, &res1);
    parsematrix(&res2, "tuesday.txt");
    multmatrix(&res1, &res2, &res3);



    parsematrix(&res3, "finalize.txt");
    multmatrix(&res2, &res1, &res3);

    outputmatrix(&res2, "result.txt");

    return 0;
}

Im not getting answer please help.

This article has been dead for over six months. Start a new discussion instead.