-
Notifications
You must be signed in to change notification settings - Fork 131
Closed
Labels
Exercise solutionSolutions to textbook exercisesSolutions to textbook exercises
Description
function count_pairs(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 count(x) {
if(! is_pair(x) || is_counted_pair(counted_pairs, x)) {
return 0;
} else {
counted_pairs = pair(x, counted_pairs);
return count(head(x)) +
count(tail(x)) +
1;
}
}
return count(x);
}
Metadata
Metadata
Assignees
Labels
Exercise solutionSolutions to textbook exercisesSolutions to textbook exercises