Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Another Elegence vs. Readability

Name: Anonymous 2011-05-31 3:57

/* Problem: We want [4][4], [4][5], [5][4], and [5][5] to all be four, and the rest to be generated between one and three */

/* snippet the first */
int arrays[10][10];
for(int i = 0; i < 10; i++){
    for(int j = 0; j < 10; j++){
        arrays[i][j] = /* randomly generate a number between one and three */;
    }
}
for(int i = 4; i < 6; i++){
    for(int j = 4; j < 6; j++){
        arrays[i][j] = 4;
    }
}

/* snippet the second */
int arrays[10][10];
for(int i = 0; i < 10; i++){
    for(int j = 0; j < 10; j++){
        if(/*  */){
            arrays[i][j] = 4;
        } else {
            arrays[i][j] = /* randomly generate a number between one and three */;
        }
    }
}


Which snippet would you use?
Excuse the pseudo-ish code.

Name: Anonymous 2011-05-31 18:16


int *c = ((int*)arrays)+100;
while( c --> arrays) *c = rand()%3 + 1;
c[45] = c[46] = c[55]  = c[56] = 4;

is the best way

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List