Slashdot Mirror


User: JoZZ

JoZZ's activity in the archive.

Stories
0
Comments
4
First seen
Last seen
Profile
(view on slashdot.org)

Comments · 4

  1. 44 lines in commented and whitespaced C. on Solving the Knight's Tour Puzzle In 60 Lines of Python · · Score: 1

    Timed with Debian on EEE 901 in HT mode (1.6 GHz Atom)

    real    0m0.726s
    user    0m0.724s
    sys     0m0.004s

    K&R (more or less), with tab-space=8 inside 79 cols. But commenting as original pyton (end of line commenting).

    -----
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    int startx = 0, starty=0, size=0; /* The size of the thing, is set in main */
    /* How knights walk, changing this changes the time outcome :) */
    int jumps[][2] = {{-2,1},{-1,2},{1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1}};

    int walk(int *board, const int x, const int y, const int step)
    {
        board[x*size+y] = step; /* set our stamp here */
        if (step == size*size)
            return 1; /* Were done */
        for (int i=0;i<8;++i) { /* for each type of jump */
            int xx = x + jumps[i][0], yy = y + jumps[i][1]; /* set new position */
            if (xx < 0 || yy < 0 || xx >= size || yy >= size || board[xx*size+yy])
                continue; /* outch. been there or outside*/
            if (walk(board, xx, yy, step + 1))
                return 1; /* were finished, just return*/
        }
        board[x*size+y] = 0; /* we could not walk anywhere, reset and ... */
        return 0; /* move back indicating failure */
    }

    void draw(const int *board, int x, int y) /* Draw the board */
    {
        for (int i=0;i<size*size;++i) {
            printf(" %4d", board[i]);
            if (((i+1) % size) == 0)
                printf("\n");
        }
    }

    int main(int argc, char *argv[])
    {
        if (argc != 2 || ((size = atoi(argv[1])) == 0)) /* get size */
            return printf("use: %s <size>\n", argv[0]) + 1;
        printf("Board of size %dx%d\n", size, size);
        unsigned int board[size*size]; /* Alloc space for board */
        memset(board, 0, sizeof(int) * size * size); /* clear space */
        walk(board, startx, starty, 1); /* Start at defined start position */
        draw(board, -1, -1); /* Draw board that is done */
        return 0; /* Yay, done */
    }

  2. Re:Maybe it's too much to ask, but . . . on Debian Desktop Subproject Launched · · Score: 1

    Hmm.. I use Debian with X installed on an old 386. Its only a Xterminal to a X-server but nonetheless X+Debian+i386. But, I do agree with you. Make it i686 I say. And have a SmallDebianDist instead. All a i386 needs is basic console tools and basic X-suff (not KDE/GNOME). Shoud not be more than a handfull of packeges (say 640MB max). My current installation isn't bigger than 100MB (but people want's different stuff)

  3. Re:Dial down the center... on Sklyarov Denied Visa to Return to U.S. for Trial · · Score: 1

    Yea an open chatroom, and then instead of layers we have an /. interview.

  4. Re:So what? on Sklyarov Denied Visa to Return to U.S. for Trial · · Score: 1

    It seems it matters to them, maby they want to clear there names.