aboutsummaryrefslogtreecommitdiff
path: root/semestr-2/racket/l14z22/solution.bak
diff options
context:
space:
mode:
Diffstat (limited to 'semestr-2/racket/l14z22/solution.bak')
-rw-r--r--semestr-2/racket/l14z22/solution.bak70
1 files changed, 70 insertions, 0 deletions
diff --git a/semestr-2/racket/l14z22/solution.bak b/semestr-2/racket/l14z22/solution.bak
new file mode 100644
index 0000000..0d4f164
--- /dev/null
+++ b/semestr-2/racket/l14z22/solution.bak
@@ -0,0 +1,70 @@
+#lang racket
+
+(require racklog)
+
+(provide solve)
+
+;; transpozycja tablicy zakodowanej jako lista list
+(define (transpose xss)
+ (cond [(null? xss) xss]
+ ((null? (car xss)) (transpose (cdr xss)))
+ [else (cons (map car xss)
+ (transpose (map cdr xss)))]))
+
+;; procedura pomocnicza
+;; tworzy listę n-elementową zawierającą wyniki n-krotnego
+;; wywołania procedury f
+(define (repeat-fn n f)
+ (if (eq? 0 n) null
+ (cons (f) (repeat-fn (- n 1) f))))
+
+;; tworzy tablicę n na m elementów, zawierającą świeże
+;; zmienne logiczne
+(define (make-rect n m)
+ (repeat-fn m (lambda () (repeat-fn n _))))
+
+;; predykat binarny
+;; (%row-ok xs ys) oznacza, że xs opisuje wiersz (lub kolumnę) ys
+(define %row-ok
+ (%rel ()
+;; TODO: uzupełnij!
+ ))
+
+;; TODO: napisz potrzebne ci pomocnicze predykaty
+
+;; funkcja rozwiązująca zagadkę
+(define (solve rows cols)
+ (define board (make-rect (length cols) (length rows)))
+ (define tboard (transpose board))
+ (define ret (%which (xss)
+ (%= xss board)
+;; TODO: uzupełnij!
+ ))
+ (and ret (cdar ret)))
+
+;; testy
+(equal? (solve '((2) (1) (1)) '((1 1) (2)))
+ '((* *)
+ (_ *)
+ (* _)))
+
+(equal? (solve '((2) (2 1) (1 1) (2)) '((2) (2 1) (1 1) (2)))
+ '((_ * * _)
+ (* * _ *)
+ (* _ _ *)
+ (_ * * _)))
+
+(equal? (solve '((4) (6) (2 2) (2 2) (6) (4) (2) (2) (2))
+ '((9) (9) (2 2) (2 2) (4) (4)))
+ '((* * * * _ _)
+ (* * * * * *)
+ (* * _ _ * *)
+ (* * _ _ * *)
+ (* * * * * *)
+ (* * * * _ _)
+ (* * _ _ _ _)
+ (* * _ _ _ _)
+ (* * _ _ _ _)))
+
+;; TODO: możesz dodać własne testy
+