diff --git a/3_16.rkt b/3_16.rkt index 5f16823..b810615 100644 --- a/3_16.rkt +++ b/3_16.rkt @@ -28,6 +28,16 @@ 1)))) (count l '())) +(define (has-cycle? l) + (define (cycle-iter l seen-pairs) + (cond ((not (pair? l)) #f) + ((memq (cdr l) seen-pairs) #t) + (else + (cycle-iter (cdr l) + (cons l seen-pairs))))) + (cycle-iter l '())) + + ;; Both give 3 (define l1 '(a b c))