From 47532e39053fffbae528e20f1b839cf603050065 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sat, 11 Jul 2020 00:46:58 +0200 Subject: [PATCH] functions: Add tbf-tabulate. --- functions.rkt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/functions.rkt b/functions.rkt index 5fbcdb3..8dbfb74 100644 --- a/functions.rkt +++ b/functions.rkt @@ -36,7 +36,8 @@ [apply-tbf/boolean (-> tbf? (vectorof boolean?) boolean?)] [list->tbf (-> (cons/c number? (cons/c number? (listof number?))) tbf?)] [read-tbfs (-> (listof (listof number?)) (listof tbf?))] - [read-org-tbfs (->* (string?) (#:headers boolean?) (listof tbf?))])) + [read-org-tbfs (->* (string?) (#:headers boolean?) (listof tbf?))] + [tbf-tabulate (-> tbf? (listof (listof (or/c 0 1))))])) (module+ test (require rackunit)) @@ -317,3 +318,16 @@ (test-case "read-org-tbfs" (check-equal? (read-org-tbfs "((1 2 1) (1 0 1))") (list (tbf '#(1 2) 1) (tbf '#(1 0) 1))))) + +;;; Tabulates a TBF. +(define (tbf-tabulate tbf) + (define ins (apply + cartesian-product + (make-list (vector-length (tbf-w tbf)) '(0 1)))) + (for/list ([in ins]) + (append in (list (apply-tbf tbf (list->vector in)))))) + +(module+ test + (test-case "tbf-tabulate" + (check-equal? (tbf-tabulate (tbf #(1 2) 1)) + '((0 0 0) (0 1 1) (1 0 0) (1 1 1)))))