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 */ }
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)
Timed with Debian on EEE 901 in HT mode (1.6 GHz Atom)
/* The size of the thing, is set in main */ :) */
/* set our stamp here */ /* Were done */ /* for each type of jump */ /* set new position */ /* outch. been there or outside*/ /* were finished, just return*/ /* we could not walk anywhere, reset and ... */ /* move back indicating failure */
/* Draw the board */
/* get size */ /* Alloc space for board */ /* clear space */ /* Start at defined start position */ /* Draw board that is done */ /* Yay, done */
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;
/* 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;
if (step == size*size)
return 1;
for (int i=0;i<8;++i) {
int xx = x + jumps[i][0], yy = y + jumps[i][1];
if (xx < 0 || yy < 0 || xx >= size || yy >= size || board[xx*size+yy])
continue;
if (walk(board, xx, yy, step + 1))
return 1;
}
board[x*size+y] = 0;
return 0;
}
void draw(const int *board, int x, int y)
{
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))
return printf("use: %s <size>\n", argv[0]) + 1;
printf("Board of size %dx%d\n", size, size);
unsigned int board[size*size];
memset(board, 0, sizeof(int) * size * size);
walk(board, startx, starty, 1);
draw(board, -1, -1);
return 0;
}
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)
Yea an open chatroom, and then instead of layers we have an /. interview.
It seems it matters to them, maby they want to clear there names.