-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path58.rkt
44 lines (39 loc) · 1.09 KB
/
58.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#lang racket
(define (flatten-map proc l)
(apply append (map proc l))
)
(define (cbal-tree n)
(cond [(zero? n) (list empty)]
[(= 1 n) (list (list 'x empty empty))]
[else
(let* ([n1 (quotient (- n 1) 2)]
[n2 (- n 1 n1)]
[c1-list (cbal-tree n1)]
[c2-list (if (= n1 n2) c1-list (cbal-tree n2))])
(flatten-map
(lambda (c1)
(flatten-map
(lambda (c2)
(if (= n1 n2)
(list (list 'x c1 c2))
(list (list 'x c1 c2) (list 'x c2 c1))))
c2-list))
c1-list))])
)
(define (mirror? a b)
(cond
[(empty? a) (empty? b)]
[(empty? b) (empty? a)]
[else (and (mirror? (cadr a) (caddr b)) (mirror? (caddr a) (cadr b)))])
)
(define (symmetirc? a)
(cond
[(empty? a) false]
[else (mirror? (cadr a) (caddr a))])
)
(define (sym-cbal-trees n)
(filter symmetirc? (cbal-tree n))
)
;------------------------------
(length (sym-cbal-trees 5))
(length (sym-cbal-trees 57))