summary refs log tree commit diff
path: root/minic/test
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-10-12 21:46:27 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-10-12 21:46:27 -0400
commit7f7cf6a03254f0ab0ec58572adda1fc92b2506a6 (patch)
treee674b657458bca3d7cef080048174258102f3946 /minic/test
parentb402c8f7d575130d08b4588f8212ad6c9ae73108 (diff)
downloadroux-7f7cf6a03254f0ab0ec58572adda1fc92b2506a6.tar.gz
add for loops
Diffstat (limited to 'minic/test')
-rw-r--r--minic/test/queen.c24
1 files changed, 6 insertions, 18 deletions
diff --git a/minic/test/queen.c b/minic/test/queen.c
index c998e2a..86058d2 100644
--- a/minic/test/queen.c
+++ b/minic/test/queen.c
@@ -8,18 +8,13 @@ print() {
 	int x;
 	int y;
 
-	y = 0;
-	while (y < 8) {
-		x = 0;
-		while (x < 8) {
+	for (y=0; y<8; y++) {
+		for (x=0; x<8; x++)
 			if (t[x + 8*y])
 				printf(" Q");
 			else
 				printf(" .");
-			x++;
-		}
 		printf("\n");
-		y++;
 	}
 	printf("\n");
 }
@@ -29,8 +24,7 @@ chk(int x, int y) {
 	int r;
 
 	r = 0;
-	i = 0;
-	while (i < 8) {
+	for (i=0; i<8; i++) {
 		r = r + t[x + 8*i];
 		r = r + t[i + 8*y];
 		if (x+i < 8 & y+i < 8)
@@ -41,11 +35,8 @@ chk(int x, int y) {
 			r = r + t[x-i + 8*(y+i)];
 		if (x-i >= 0 & y-i >= 0)
 			r = r + t[x-i + 8*(y-i)];
-		if (r)
-			return 1;
-		i++;
 	}
-	return 0;
+	return r;
 }
 
 go(int n, int x, int y) {
@@ -54,17 +45,14 @@ go(int n, int x, int y) {
 		N++;
 		return 0;
 	}
-	while (y < 8) {
-		while (x < 8) {
+	for (; y<8; y++) {
+		for (; x<8; x++)
 			if (chk(x, y) == 0) {
 				t[x + 8*y]++;
 				go(n+1, x, y);
 				t[x + 8*y]--;
 			}
-			x++;
-		}
 		x = 0;
-		y++;
 	}
 }