diff --git a/ack.rkt b/ack.rkt new file mode 100644 index 0000000..eccb418 --- /dev/null +++ b/ack.rkt @@ -0,0 +1,7 @@ +;; The first three lines of this file were inserted by DrRacket. They record metadata +;; about the language level of this file in a form that our tools can easily process. +#reader(lib "htdp-advanced-reader.ss" "lang")((modname ack) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f () #f))) +(define (ack n m) + (cond [(= 0 n) (+ m 1)] + [(= 0 m) (ack (- n 1) 1)] + [else (ack (- n 1) (ack n (- m 1)))])) \ No newline at end of file diff --git a/bst.rkt b/bst.rkt index 9256ee6..266f6b9 100644 --- a/bst.rkt +++ b/bst.rkt @@ -108,4 +108,9 @@ [(empty? node) empty] [(empty? (node-left node)) (node-right node)] [(empty? (node-right node)) (node-left node)] - [else (make-node (node-value (replacement node)) (sans-max-subtree (node-left node)) (node-right node))])) \ No newline at end of file + [else (make-node (node-value (replacement node)) (sans-max-subtree (node-left node)) (node-right node))])) + +(check-equal? (delete empty) empty) +(check-equal? (delete (make-node 5 empty empty)) empty) +(check-equal? (make-node 5 empty empty) (make-node 5 empty empty)) +(check-equal? (delete (make-node 6 (make-node 2 empty empty) empty)) (make-node 2 empty empty)) \ No newline at end of file diff --git a/fop-klausur.rkt b/fop-klausur.rkt new file mode 100644 index 0000000..841c06c --- /dev/null +++ b/fop-klausur.rkt @@ -0,0 +1,20 @@ +;; The first three lines of this file were inserted by DrRacket. They record metadata +;; about the language level of this file in a form that our tools can easily process. +#reader(lib "htdp-advanced-reader.ss" "lang")((modname fop-klausur) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f () #f))) +(define-struct abc (a b)) + +(define (foo p) + (if (abc? p) + (if (list? (abc-b p)) + (cons (abc-a p) (abc-b p)) + empty) + empty)) + +(define (bar lst n) + (cond + [(= 0 n) empty] + [(< (length lst) n) lst] + [else (cons (first lst) (bar (rest lst) (- n 1)))])) + +(define (foo-bar n) + (lambda (x) (bar x n))) \ No newline at end of file diff --git a/pascal-line.rkt b/pascal-line.rkt new file mode 100644 index 0000000..c7e7b95 --- /dev/null +++ b/pascal-line.rkt @@ -0,0 +1,10 @@ +;; The first three lines of this file were inserted by DrRacket. They record metadata +;; about the language level of this file in a form that our tools can easily process. +#reader(lib "htdp-advanced-reader.ss" "lang")((modname pascal-line) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f () #f))) +(define (pascal-line n) + (cond [(= n 0) (list 1)] + [else (new-pascal-line (append (list 0) (pascal-line (- n 1)) (list 0)))])) + +(define (new-pascal-line l) + (cond [(< (length l) 2) empty] + [else (cons (+ (first l) (second l)) (new-pascal-line (rest l)))])) \ No newline at end of file diff --git a/substr.rkt b/substr.rkt new file mode 100644 index 0000000..6eff8b3 --- /dev/null +++ b/substr.rkt @@ -0,0 +1,14 @@ +;; The first three lines of this file were inserted by DrRacket. They record metadata +;; about the language level of this file in a form that our tools can easily process. +#reader(lib "htdp-advanced-reader.ss" "lang")((modname substr) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f () #f))) +(define (is-substring? s sub) + (is-substring-expl? (explode s) (explode sub) (explode sub))) + +(define (is-substring-expl? s sub backup) + (cond [(empty? sub) #t] + [(empty? s) #f] + [(equal? (first s) (first sub)) + (is-substring-expl? (rest s) (rest sub) backup)] + [(equal? (first s) (first backup)) + (is-substring-expl? (rest s) (rest backup) backup)] + [else (is-substring-expl? (rest s) sub backup)])) \ No newline at end of file