Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
Back to list of problems

The House Of Santa Claus

291.c

/* 291 - The House Of Santa Claus */

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


typedef struct {
	int a;
	int b;
} edge;

#define NUM_EDGES 8
edge edges[NUM_EDGES] = {{1,2}, {1,3}, {1,5}, {2,3}, {2,5}, {3,4}, {3,5}, {4,5}};

int visited[NUM_EDGES];

int order[9];

void
recorre(int n, int o) {
	int i;

	order[o] = n;

	if (o==8) {
		for (i=0; i<9; i++) {
			printf("%d", order[i]);
		}
		printf("\n");
		return;
	}

	for (i=0; i<NUM_EDGES; i++) {
		if (!visited[i]) {
			if (edges[i].a==n) {
				visited[i] = 1;
				recorre(edges[i].b, o+1);
				visited[i] = 0;
			} else if (edges[i].b==n) {
				visited[i] = 1;
				recorre(edges[i].a, o+1);
				visited[i] = 0;
			}
		}
	}
}

int
main(void) {
	memset(visited, 0, sizeof(visited));
	recorre(1,0);

	return 0;
}