diff --git a/xml/chapter3/section3/subsection1.xml b/xml/chapter3/section3/subsection1.xml
index 08c5fcc71..ed023d843 100644
--- a/xml/chapter3/section3/subsection1.xml
+++ b/xml/chapter3/section3/subsection1.xml
@@ -1592,6 +1592,50 @@ display(count_pairs(cycle));
would go into an infinite loop. Exercise
constructed such lists.
+
+
+ exercise_3_18_solution_example
+
+// solution provided by GitHub user clean99
+
+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;
+ } else if (is_counted_pair(counted_pairs, x)) {
+ return true;
+ } else {
+ counted_pairs = pair(x, counted_pairs);
+ return detect_cycle(tail(x));
+ }
+ }
+ return detect_cycle(x);
+}
+
+
+
+ exercise_3_18_solution_example
+
+const three_list = list("a", "b", "c");
+const cycle = list("g", "h", "i");
+set_tail(tail(tail(cycle)), cycle);
+
+// displays false
+display(contains_cycle(three_list));
+
+// displays true
+display(contains_cycle(cycle));
+
+
+