연습문제 3.18, 3.19

2 views
Skip to first unread message

xeraph

unread,
Jan 30, 2008, 1:10:23 AM1/30/08
to sicp-sig
그냥 19번을 풀고 18번은 무시했습니다. 19가 더 공간 효율적인 것이라..

(define (cycle? lst)
(define (race tortoise hair)
(cond ((eq? tortoise hair) #t)
((null? tortoise) #f)
((null? hair) #f)
((null? (cdr tortoise)) #f)
((null? (cdr hair)) #f)
(else (race (cdr tortoise) (cddr hair)))))

(race (cdr lst) (cddr lst)))

(define cycle '(a b c))
(set-cdr! (cddr cycle) cycle)
(cycle? cycle)
(cycle? '(1 2 3 4 5))

xeraph

unread,
Jan 30, 2008, 1:20:20 AM1/30/08
to sicp-sig
흑.. 바보같이.. hair 아니고 hare임 orz..
Reply all
Reply to author
Forward
0 new messages