; just split up in cases:
; Braun tree with one node has height 0
; Braun tree with two nodes has height 1
; Braun tree with more than two nodes has height exactly one more
; than the height of its bigger subtree; the numbers below correspond
; exactly to the size of the bigger subtree (actually, when there's odd
; number of nodes in the tree, then both subtrees are of equal size, so
; we can pick any)
(define (braunheight n)
(cond ((= n 1) 0)
((= n 2) 1)
((odd? n) (+ 1 (braunheight (/ (- n 1) 2))))
((even? n) (+ 1 (braunheight (/ n 2))))
))
; we don't need to test numbers for primality here; if the number is
; divisible by any square, then its not square free
(define (sqfree n)
(define (aux i n)
(if (<= i (sqrt n))
(if (= (modulo n (* i i)) 0)
#f
(aux (+ i 1) n))
#t))
(aux 2 n)
)