-
Notifications
You must be signed in to change notification settings - Fork 131
Closed
Labels
Exercise solutionSolutions to textbook exercisesSolutions to textbook exercises
Description
function contains_cycle(x) {
let counted_pairs = null;
function is_counted_pair(counted_pairs, x) {
return is_null(counted_pairs)
? false
: head(counted_pairs) === x
? true
: is_counted_pair(tail(counted_pairs), x);
}
function detect_cycle(x) {
if(is_null(x)) {
return false;
}
if(is_counted_pair(counted_pairs, x)) {
return true;
}
counted_pairs = pair(x, counted_pairs);
return detect_cycle(tail(x));
}
return detect_cycle(x);
}
Metadata
Metadata
Assignees
Labels
Exercise solutionSolutions to textbook exercisesSolutions to textbook exercises