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
commit79c11b29d78a70ae1b04af3b7ca4ec9bb12dd8d7 (patch)
treec4577e59ae13a8031f937991dcc3a63f68d18db5 /nqueens.c
parent62eb92d94fa902b4a34dafce45547680a2655b40 (diff)
parent7aacc9f2510901c9e97b30fa9bcb550bb7f99c03 (diff)
Merge tag 'upstream/0.5.1+git20170605'
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;
-}