aboutsummaryrefslogtreecommitdiff
path: root/nqueens.c
diff options
context:
space:
mode:
authorSimon Quigley <tsimonq2@ubuntu.com>2017-06-19 15:19:47 -0500
committerSimon Quigley <tsimonq2@ubuntu.com>2017-06-19 15:19:47 -0500
commit7aacc9f2510901c9e97b30fa9bcb550bb7f99c03 (patch)
tree16908948750c11da8332d80d8bb9b339399ee4d7 /nqueens.c
parent7c47b5b9584f5011aeba18d7e1b26b3d3124825f (diff)
New upstream version 0.5.1+git20170605
Diffstat (limited to 'nqueens.c')
-rw-r--r--nqueens.c37
1 files changed, 0 insertions, 37 deletions
diff --git a/nqueens.c b/nqueens.c
deleted file mode 100644
index 838731c4..00000000
--- a/nqueens.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * N-Queens Problem Solver
- * Found somewhere on the Internet; can't remember where. Possibly Wikipedia.
- */
-#include <stdio.h>
-#include <stdbool.h>
-#include <stdlib.h>
-
-#define QUEENS 11
-
-int row[QUEENS];
-
-bool safe(int x, int y)
-{
- int i;
- for (i = 1; i <= y; i++)
- if (row[y - i] == x || row[y - i] == x - i || row[y - i] == x + i)
- return false;
- return true;
-}
-
-int nqueens(int y)
-{
- int x;
-
- for (x = 0; x < QUEENS; x++) {
- if (safe((row[y - 1] = x), y - 1)) {
- if (y < QUEENS) {
- nqueens(y + 1);
- } else {
- break;
- }
- }
- }
-
- return 0;
-}