Last active
January 4, 2016 13:19
-
-
Save rgm/8627518 to your computer and use it in GitHub Desktop.
Floyd's algorithm for SICP exercise 3.19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (has-cycle? ls) | |
(define (has-cycle-h tortoise hare) | |
(cond ((null? hare) #f) | |
((null? (cdr hare)) #f) | |
((eq? (car tortoise) (car hare)) #t) | |
(else | |
(has-cycle-h (cdr tortoise) (cddr hare))))) | |
(cond ((null? ls) #f) | |
(else (has-cycle-h ls (cdr ls))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Purty. Note the complete absence of
set!
.(Courtesy of http://en.literateprograms.org/Floyd's_cycle-finding_algorithm_(Scheme))