All pastes #410074 Raw Edit

Mine

public text v1 · immutable
#410074 ·published 2007-03-26 02:46 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>

#define XY(x,y)         xyboard[y][x] = f
#define DE_XY(x,y)      xyboard[y][x] = 0
#define XY_LOC(x,y)     printf("(%d, %d) = %d\n", x, y, &xyboard[y][x] - board)
#define P(x,y)          {\
                            XY(x,y);\
                            XY_LOC(x,y);\
                        }

int main(int argc, char **argv) {
    char *board;
    char **xyboard;
    int x, y, p, f;
    int dim = atoi(argv[1]);
    if (dim < 1 || dim > 0x8fff) {
        printf("Invalid board size\n");
        return(1);
    }

    board = (char *)malloc(dim * dim * sizeof(char));

    xyboard = (char **)malloc(dim * sizeof(char *));
    for (y = 0; y < dim; y++)
        xyboard[y] = &board[y * dim];

    for (f = 1, p = 0; p < 5; p++)
        P((dim + 5 + p) % dim, (p + 2) % dim);

    for (f = 2, p = 0; p < 5; p++)
        P((dim - p + 1) % dim, p % dim);

    for (y = 0; y < dim; y++) {
        for (x = 0; x < dim; x++) {
            p = y * dim + x;
            printf("%d ", board[p]);
        }
        printf("\n");
    }
    return(0);
}