rendered paste body;Aufgabe 2
(define (collatz i); Diese Prozedur ist konstant O(1)
(if (even? i)
(/ i 2)
(+ (* i 3) 1))
)
;(collatz 7);-->22
(define (collatz-length i)
(define (laenge i n)
(if (> i 1)
(laenge (collatz i) (+ n 1))
n)
)
(laenge i 1)
)
;(collatz-length 6);-->9
(define (collatz-longest n)
(define (zaehlen i momlmax momimax)
(cond ((<= i n)
(if (< (collatz-length i) momlmax) (zaehlen (+ i 1) momlmax momimax) (zaehlen (+ i 1) (collatz-length i) i)))
(else (display "Die längste Collatz-Folge ist ") (display momimax) (display " mit der Länge ") (display momlmax) (newline) (display momlmax)))
)
(zaehlen 0 0 0)
)
(collatz-longest 10000)