From 42497f9cbe935590b6b75263a56a7d9e31ab805e Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Wed, 4 Jul 2007 19:55:16 +0000 Subject: [PATCH] reverted accidental commit [r14939] --- ir/be/test/Queens.c | 59 +++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/ir/be/test/Queens.c b/ir/be/test/Queens.c index f50bcfe36..2c1015b64 100644 --- a/ir/be/test/Queens.c +++ b/ir/be/test/Queens.c @@ -32,54 +32,49 @@ static int myabs(int i) { return(i); } -boolean place_ok (int i) { +static boolean place_ok (int i) { // return whether queen in column i is // not in check from queens left of it int j = 0; boolean res; - printf("POK: %d\n", i); - while (j < i) { if ((row[j] == row[i]) || ((myabs(row[i]-row[j])) == (i-j))) { - printf("F\n"); res = false; return(res); } j = j+1; } - printf("T\n"); res = true; return(res); } -int solve (int n) { - // return the number of solutions to the n-queens problem - int c = 0; - int res = 0; - - row = (void *)malloc(sizeof(*row) * n); - row[0] = -1; - while (c >= 0) { - row[c] = row[c]+1; - while ((row[c] < n) && (!place_ok(c))) { - row[c] = row[c]+1; - } - printf("RC: %d\n", row[c]); - if (row[c] < n) { // successfully placed at (c,row[c]) - if (c == n-1) - res = res+1; - else { - c = c+1; - row[c] = -1; - } - } - else // dead end, track back - c = c-1; - } - free(row); - - return(res); +static int solve (int n) { + // return the number of solutions to the n-queens problem + int c = 0; + int res = 0; + + row = (void *)malloc(sizeof(*row) * n); + row[0] = -1; + while (c >= 0) { + row[c] = row[c]+1; + while ((row[c] < n) && (!place_ok(c))) { + row[c] = row[c]+1; + } + if (row[c] < n) { // successfully placed at (c,row[c]) + if (c == n-1) + res = res+1; + else { + c = c+1; + row[c] = -1; + } + } + else // dead end, track back + c = c-1; + } + free(row); + + return(res); } static void usage (const char *progname) { -- 2.20.1