Skip to content
This repository
Browse code

43.3.2

  • Loading branch information...
commit 43c4a99c177fae640933cfbff009a3814bfe1cc3 1 parent 2061f25
Jeong-Min Lee authored June 11, 2012
6  43/43.3.1.scm
... ...
@@ -1,5 +1,9 @@
1 1
 #lang racket
2 2
 
  3
+(provide
  4
+  board-for-all
  5
+  place-queen)
  6
+
3 7
 (define (board-for-all f board)
4 8
   (local ((define N (vector-length board)))
5 9
     (for-each (lambda (i)
@@ -45,4 +49,4 @@
45 49
     )
46 50
    ))
47 51
 
48  
-(exit (run-tests place-queen-tests))
  52
+(run-tests place-queen-tests)
40  43/43.3.2.scm
... ...
@@ -0,0 +1,40 @@
  1
+#lang racket
  2
+
  3
+(require "43.3.1.scm")
  4
+
  5
+(define (unplace-queen board i j)
  6
+  (board-for-all
  7
+    (lambda (I J x)
  8
+      (cond [(or (= i I)
  9
+                 (= j J)
  10
+                 (= (+ i j) (+ I J))
  11
+                 (= (- i j) (- I J))) true]
  12
+            [else x]))
  13
+    board))
  14
+
  15
+(require rackunit)
  16
+(require rackunit/text-ui)
  17
+
  18
+(define unplace-queen-tests
  19
+  (test-suite
  20
+   "Test for unplace-queen"
  21
+
  22
+   (test-case
  23
+    ""
  24
+    (define board
  25
+      (build-vector
  26
+        3
  27
+        (lambda (i)
  28
+          (build-vector
  29
+            3
  30
+            (lambda (j) false)))))
  31
+    (unplace-queen board 0 0)
  32
+    (check-equal?
  33
+      board
  34
+      '#(#(#t #t #t)
  35
+         #(#t #t #f)
  36
+         #(#t #f #t)))
  37
+    )
  38
+   ))
  39
+
  40
+(exit (run-tests unplace-queen-tests))

0 notes on commit 43c4a99

Please sign in to comment.
Something went wrong with that request. Please try again.